检查文件或目录的存在
import java.nio.file.FileSystems;//时 代 J a v a 公 众 号 import java.nio.file.Files; import java.nio.file.LinkOption; import java.nio.file.Path; public class Main { public static void main(String[] args) { Path path = FileSystems.getDefault().getPath( "C:/folder1/folder2/folder4", "test2.txt"); boolean path_exists = Files.exists(path, new LinkOption[] { LinkOption.NOFOLLOW_LINKS }); } }