-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathReadFileExample.java
More file actions
23 lines (20 loc) · 891 Bytes
/
Copy pathReadFileExample.java
File metadata and controls
23 lines (20 loc) · 891 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.StandardOpenOption;
public class ReadFileExample {
public static void main(String[] args) {
try {
String content = Files.readString(Paths.get("/Users/harinit/Desktop/javacourse/JavaPrograms/JavaPrograms/src/example.txt"));
System.out.println(content);
Path p = Path.of("/Users/harinit/Desktop/javacourse/JavaPrograms/JavaPrograms/src/example_copy.txt");
Files.writeString(p,"Added new lines", StandardOpenOption.APPEND);
String s1 = Files.readString(p);
//Files.writeString(p,"Added new lines with new options", StandardOpenOption.APPEND);
System.out.println(s1);
} catch (IOException e) {
e.printStackTrace();
}
}
}