-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFileExample.java
More file actions
29 lines (23 loc) · 845 Bytes
/
Copy pathFileExample.java
File metadata and controls
29 lines (23 loc) · 845 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
package Java11;
import java.io.File;
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 FileExample {
public static void main(String[] args) throws IOException {
System.out.println("File Operations after Java 11");
System.out.println("Read Operation");
System.out.println(readString1(new File("example.txt")));
System.out.println("Write Operation");
writeString("Hello");
}
static String readString1(File file) throws IOException {
return Files.readString(Path.of(file.toURI()));
}
public static void writeString(String fileContent) throws IOException {
Files.writeString(Paths.get("exampleWrite.txt"), fileContent,
StandardOpenOption.CREATE);
}
}