-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDataStreamExample.java
More file actions
47 lines (37 loc) · 1 KB
/
DataStreamExample.java
File metadata and controls
47 lines (37 loc) · 1 KB
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
/**
*
*/
package filesIO;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
/**
* @author rutpatel
*
*/
public class DataStreamExample {
public static void main(String[] args) throws IOException {
File f = new File("data.txt");
FileOutputStream fos = new FileOutputStream(f);
DataOutputStream dos = new DataOutputStream(fos);
dos.writeBoolean(false);
dos.writeDouble(12.2);
dos.writeInt(1);
dos.writeBytes("Hello");
dos.flush();
System.out.println("-----Data Added-----");
FileInputStream fis = new FileInputStream(f);
DataInputStream dis = new DataInputStream(fis);
System.out.println("----Reading Data----");
System.out.println(dis.readBoolean());
System.out.println(dis.readDouble());
System.out.println(dis.readInt());
System.out.println(new String(dis.readAllBytes()));
// System.out.println(dis.readLine());
dos.close();
dis.close();
}
}