java.nio.file.Path Methods
for working with files and directories in NIO
Path path = Paths.get("example.txt");
Path path = Paths.get("example.txt"); if (Files.exists(path)) { System.out.println("File exists."); } else { System.out.println("File does not exist."); }Path path = Paths.get("example.txt"); if (Files.isRegularFile(path)) { System.out.println("It's a regular file."); }Path path = Paths.get("mydirectory"); if (Files.isDirectory(path)) { System.out.println("It's a directory."); }
Path path = Paths.get("example.txt"); Path absolutePath = path.toAbsolutePath();Path path = Paths.get("example.txt"); Path fileName = path.getFileName();
Path path = Paths.get("example.txt"); if (Files.isReadable(path)) { System.out.println("File is readable."); }Path path = Paths.get("example.txt"); if (Files.isWritable(path)) { System.out.println("File is writable."); }
Last updated