forked from deepdalsania/tutorials
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSerialization.java
More file actions
55 lines (48 loc) · 1.65 KB
/
Serialization.java
File metadata and controls
55 lines (48 loc) · 1.65 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
48
49
50
51
52
53
54
55
package file;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
public class Serialization {
/**
* @param args
* @throws IOException
* @throws FileNotFoundException
* @throws ClassNotFoundException
*/
public static void main(String[] args) throws FileNotFoundException, IOException, ClassNotFoundException {
// TODO Auto-generated method stub
System.out.println("<< SERIALIZATION >>");
File f = new File("D:/DEEP/eight.txt");
ObjectOutputStream oo = new ObjectOutputStream(new FileOutputStream(f));
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter name of student : ");
oo.writeObject(br.readLine()+" , ");
System.out.println("Enter Enrollment number : ");
long i = Long.parseLong(br.readLine());
oo.writeObject(i+" , ");
System.out.println("Total marks : ");
int tot = Integer.parseInt(br.readLine());
oo.writeObject(tot+" , ");
float avg = (float)tot/5 ;
System.out.println("Average is : "+avg);
oo.writeObject(avg);
oo.close();
System.out.println("<< DESERIALIZATION >>");
ObjectInputStream oi = new ObjectInputStream(new FileInputStream(f));
/*Object o = oi.readObject()() ;
while ((o = oi.readObject()) != null) {
System.out.println(o);
}*/
System.out.println(oi.readObject());
System.out.println(oi.readObject());
System.out.println(oi.readObject());
System.out.println(oi.readObject());
oi.close();
}
}