-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathStoringAndRecoveringData.java
More file actions
41 lines (33 loc) · 987 Bytes
/
StoringAndRecoveringData.java
File metadata and controls
41 lines (33 loc) · 987 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
package io;
import java.io.*;
import java.util.*;
/**
* RUN:
* javac io/StoringAndRecoveringData.java && java io.StoringAndRecoveringData
*
* OUTPUT:
*
*/
public class StoringAndRecoveringData {
public static void main(String[] args) throws IOException {
DataOutputStream out = new DataOutputStream(
new BufferedOutputStream(
new FileOutputStream("io/Data.txt")
)
);
out.writeDouble(3.14159);
out.writeUTF("That was pi");
out.writeDouble(1.41413);
out.writeUTF("Square root of 2");
out.close();
DataInputStream in = new DataInputStream(
new BufferedInputStream(
new FileInputStream("io/Data.txt")
)
);
System.out.println(in.readDouble());
System.out.println(in.readUTF());
System.out.println(in.readDouble());
System.out.println(in.readUTF());
}
}