String filename = "path/to/file.txt"; String content = new String(Files.readAllBytes(Paths.get(filename)));
String filename = "path/to/file.txt"; String content = "Hello, World!"; byte[] bytes = content.getBytes(); Files.write(Paths.get(filename), bytes);
String filename = "path/to/file.txt"; if (Files.exists(Paths.get(filename))) { System.out.println("File exists!"); } else { System.out.println("File does not exist."); }All of these code examples use the java.nio.file.Files class, which is part of the Java NIO package library.