The NIO.2 File API (java.nio.file) introduces Path and Files for better file management, offering methods to easily read from and write to files.
Source Code
Path path = Paths.get("somefile.txt");
try {
Files.writeString(path, "Hello, New I/O!"); // Write string to a file
String content = Files.readString(path); // Read string from a file
System.out.println(content);
} catch (IOException e) {
e.printStackTrace();
}