How do I check if a file exists in Java?

后端 未结 17 2415
盖世英雄少女心
盖世英雄少女心 2020-11-22 00:50

How can I check whether a file exists, before opening it for reading in Java (the equivalent of Perl\'s -e $filename

17条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-11-22 01:17

    There is specific purpose to design these methods. We can't say use anyone to check file exist or not.

    1. isFile(): Tests whether the file denoted by this abstract pathname is a normal file.
    2. exists(): Tests whether the file or directory denoted by this abstract pathname exists. docs.oracle.com

提交回复
热议问题