Java 如何在项目开始运行时检查文件是否存在?
我是java编程新手,所以也许我的问题对你们中的一些人来说很愚蠢 我在java web项目中使用netbeans。 无论何时启动projecct,我都需要检查文件系统中是否存在某些文件 所以,我想知道我可以在哪里放置函数来检查文件是否存在(例如,projset中的启动项目在哪里) 项目启动时在操作系统中?Java1或更高版本 Java7或更高版本Java 如何在项目开始运行时检查文件是否存在?,java,Java,我是java编程新手,所以也许我的问题对你们中的一些人来说很愚蠢 我在java web项目中使用netbeans。 无论何时启动projecct,我都需要检查文件系统中是否存在某些文件 所以,我想知道我可以在哪里放置函数来检查文件是否存在(例如,projset中的启动项目在哪里) 项目启动时在操作系统中?Java1或更高版本 Java7或更高版本 File file = new File("c:/foo.txt"); file.isFile(); // true - file is r
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
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