【发布时间】:2015-12-30 19:08:06
【问题描述】:
到目前为止,我提出了这个解决方案,但我想知道是否有更有效的方法来做到这一点。 伪代码:
public static void main(String args[]){
boolean FileNotFound = false;
FileReader file = new FileReader("path");
try (BufferedReader bReader = new BufferedReader(file){
//nothing to execute here
}catch (FileNotFoundException e) {
FileNotFound = true;
}
if (FileNotFound) {
//generate the file
}
}
【问题讨论】:
-
File.exists()? -
如果你想确保它是一个文件,而不是一个目录,使用
File.isFile()