到目前为止,我带来了这个解决方案,但我想知道是否有更有效的方法来做到这一点。 伪代码:
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
}
}
答案 0 :(得分:1)
只需使用
public static boolean fileExists(String path) {
File file = new File(path);
return file.exists();
}
然后只需用
调用它...
if(fileExists("path")) ...
...