Close

Java IO & NIO - java.nio.file.Files Examples

Java IO & NIO Java 

Read/Write File

    private void writeData (String path, String data) {
synchronized (getLock(path)) {
try {
Files.write(Paths.get(path), data.getBytes());
} catch (IOException e) {
e.printStackTrace();
}
}
}

private void readData (String path) {
synchronized (getLock(path)) {
String s = null;
try {
s = new String(Files.readAllBytes(Paths.get(path)));
} catch (IOException e) {
e.printStackTrace();
}
System.out.println(s);
}
}
Original Post




See Also