-
Notifications
You must be signed in to change notification settings - Fork 0
/
Advance_IO.java
74 lines (53 loc) · 1.44 KB
/
Advance_IO.java
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.PrintWriter;
public class Advance_IO {
public static void main(String[] args) {
// TODO Auto-generated method stub
String str = "MN";
int value = 125;
PrintWriter pw = null;
try {
pw = new PrintWriter("output.txt");
pw.println(str); // write a string
pw.println(value); // write an integer
pw.close();
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
FileOutputStream fos = null;
try {
fos = new FileOutputStream("output.bin");
for(char c: str.toCharArray())
fos.write(c);
fos.write(value);
fos.close();
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
FileInputStream fis = null;
try {
fis = new FileInputStream("output.bin");
int next = fis.read();
while(next != -1) {
System.out.println(next);
next = fis.read();
}
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}