-
Notifications
You must be signed in to change notification settings - Fork 0
/
Deserialize.java
77 lines (61 loc) · 2.17 KB
/
Deserialize.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
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
package New;
import java.io.*;
import java.util.ArrayList;
public class Deserialize {
static ArrayList<MailData> emp = new ArrayList<>();
public static ArrayList<MailData> look() {
try {
File filename = new File("SentEmails.ser");
FileInputStream fileInputStream = new FileInputStream(filename);
ObjectInputStream objectInputStream = null;
MailData sendMail;
do {
try {
try {
objectInputStream = new ObjectInputStream(fileInputStream);
sendMail = (MailData) objectInputStream.readObject();
emp.add(sendMail);
} catch (EOFException e) {
break;
}
} catch (EOFException e) {
e.printStackTrace();
break;
}
} while (sendMail != null);
assert objectInputStream != null;
objectInputStream.close();
fileInputStream.close();
return emp;
} catch (IOException | ClassNotFoundException e) {
System.out.println("Error occured.");
e.printStackTrace();
}
return null;
}
}
/*import java.io.*;
public class Deserialize {
public static void look() {
Employee e = null;
//while
try {
FileInputStream fileIn = new FileInputStream("employee.ser");
ObjectInputStream in = new ObjectInputStream(fileIn);
e = (Employee) in.readObject();
in.close();
fileIn.close();
} catch (IOException i) {
i.printStackTrace();
return;
} catch (ClassNotFoundException c) {
System.out.println("Employee class not found");
c.printStackTrace();
return;
}
System.out.println("Deserialized Employee...");
System.out.println("Name: " + e.name);
System.out.println("Address: " + e.address);;
System.out.println("Number: " + e.number);
}
}*/