-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFileReadWriteBytes.java
More file actions
26 lines (24 loc) · 900 Bytes
/
FileReadWriteBytes.java
File metadata and controls
26 lines (24 loc) · 900 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
import java.io.*;
public class FileReadWriteBytes {
public static void main(String[] args) {
try (FileOutputStream fr = new FileOutputStream("abc.txt")) {
String text = "I am Aditya Kumar\nfrom Meerut";
byte[] b = text.getBytes();
fr.write(b);
} catch (IOException e) {
System.out.println(e);
}
try (BufferedReader br = new BufferedReader(new FileReader("abc.txt"));
FileOutputStream r = new FileOutputStream("ded.txt")) {
String p;
while ((p = br.readLine()) != null) {
byte[] arr = p.getBytes();
r.write(arr);
r.write('\n');
}
System.out.println("Successfully copied content to ded.txt!");
} catch (IOException e) {
System.out.println(e);
}
}
}