The java.nio.file package offers a more versatile approach to file I/O operations compared to java.io.
Source Code
import java.nio.file.*;
import java.io.IOException;
public class ReadFileNio {
public static void main(String[] args) {
Path filePath = Paths.get("example.txt");
try {
String content = Files.readString(filePath);
System.out.println(content);
} catch (IOException e) {
e.printStackTrace();
}
}
}