forked from deepdalsania/tutorials
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPath_nio.java
More file actions
46 lines (30 loc) · 891 Bytes
/
Path_nio.java
File metadata and controls
46 lines (30 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
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package niopkg;
import java.io.InputStream;
import java.io.OutputStream;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
// read and Write From the File By Using Java NIO package
public class Path_nio {
public static void main(String[] args) {
try {
// Specify the File
Path filePath = Paths.get("G:/1.txt");
// For Write The data
OutputStream outputStream = Files.newOutputStream(filePath);
// Write String as Bytes
outputStream.write("Write Data Using JAVA_NIO".getBytes());
outputStream.close();
// For read the Data
InputStream inputStream = Files.newInputStream(filePath);
// read Status
int readStatus = 1;
// One by One Character Read from the File
while ((readStatus = inputStream.read()) != -1) {
System.out.print((char) readStatus);
}
} catch (Exception e) {
}
}
}
kkothari_3