-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBankAccountHashTest.java
More file actions
109 lines (84 loc) · 2.27 KB
/
Copy pathBankAccountHashTest.java
File metadata and controls
109 lines (84 loc) · 2.27 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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;
import java.util.HashSet;
public class BankAccountHashTest{
public static void main(String[] args) {
StudentDetails obj1 = new StudentDetails("Vedangi", 101);
StudentDetails obj2 = new StudentDetails("Pooja", 102);
StudentDetails obj3 = new StudentDetails("Shweta", 103);
StudentDetails obj4 = new StudentDetails("Shravani", 100);
HashSet<StudentDetails> hs = new HashSet<StudentDetails>();
hs.add(obj1);
hs.add(obj2);
hs.add(obj3);
hs.add(obj4);
DemoSer serObj = new DemoSer();
serObj.serialize(hs);
serObj.deserialize();
}
}
class StudentDetails implements Serializable
{
private String name;
private int rollNo;
public StudentDetails(String name, int rollNo) {
super();
this.name = name;
this.rollNo = rollNo;
}
@Override
public String toString() {
return "StudentDetails [name=" + name + ", rollNo=" + rollNo + "]";
}
}
class DemoSer
{
void serialize(HashSet<StudentDetails> h)
{
try
{
FileOutputStream fout = new FileOutputStream("C:\\Users\\MY pc\\Desktop\\serializeObject.txt");
System.out.println("File created for writing...");
ObjectOutputStream oos = new ObjectOutputStream(fout);
oos.writeObject(h);
oos.close();
fout.close();
}
catch(FileNotFoundException e)
{
e.printStackTrace();
}
catch (IOException e)
{
e.printStackTrace();
}
}
void deserialize()
{
try
{
FileInputStream fin = new FileInputStream("C:\\Users\\MY pc\\Desktop\\serializeObject.txt");
ObjectInputStream ois = new ObjectInputStream(fin);
HashSet<StudentDetails> h = new HashSet<StudentDetails>();
h = (HashSet<StudentDetails>) ois.readObject();
for(StudentDetails s: h)
{
System.out.println(" "+s);
}
}
catch(FileNotFoundException e)
{
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
}
}