要仅在文件不存在时采取措施,请调用notExists()方法
import java.nio.file.FileSystems; import java.nio.file.Files; import java.nio.file.LinkOption;/** from NowJava.com - 时 代 Java**/ 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_notexists = Files.notExists(path, new LinkOption[] { LinkOption.NOFOLLOW_LINKS }); } }