-
Notifications
You must be signed in to change notification settings - Fork 0
/
SerializationDemo.java
38 lines (35 loc) · 1.02 KB
/
SerializationDemo.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
import java.io.*;
class StudentSerial implements Serializable
{
private int rollno;
private String name;
private String dept;
private float avg;
StudentSerial(){}
StudentSerial(int r, String n, float a, String d)
{
rollno=r;
name=n;
avg=a;
dept=d;
}
public String toString(){
return"\nStudent Details\n" +
"\nRoll "+rollno+
"\nName "+name+
"\nAverage "+avg+
"\nDept "+dept+"\n";
}
}
public class SerializationDemo {
public static void main(String[] args)throws Exception {
FileInputStream fis = new FileInputStream("I:/Student3.txt");
ObjectInputStream ois = new ObjectInputStream(fis);
// StudentSerial s = new StudentSerial(10,"Tushar Joshi", (float) 8.55,"CSE");
// oos.writeObject(s);
StudentSerial s = (StudentSerial) ois.readObject();
System.out.println(s);
fis.close();
ois.close();
}
}