我是Java编程新手,所以也许我的问题在你们中的一些人看来很愚蠢。
我将 netbeans 用于我的 Java Web 项目。每当触发 projecct 时,我都需要检查文件系统中是否存在某些文件。
所以,我想知道我可以在哪里放置函数来检查文件是否存在(即 projcet 中的启动项目在哪里)项目开始时在操作系统中?
Java1 或 higer
File file = new File("c:/foo.txt");
file.isFile(); // true - file is regular file (not a directory or smth. else)
file.exists(); // true - file exists
file.canRead(); // true - file exists and readable
file.canWrite(); // true - file exists and writable
Java7 或更高版本
Path file = Paths.get("c:/foo.txt");
Files.isRegularFile(file); // true - file is regular file (not a directory or smth. else)
Files.exists(file); // true - file exists
Files.isReadable(file); // true - file exists and readable
Files.isWritable(file); // true - file exists and writable