-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathReadObjects.java
More file actions
37 lines (28 loc) · 882 Bytes
/
Copy pathReadObjects.java
File metadata and controls
37 lines (28 loc) · 882 Bytes
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
package tutorial35;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.util.ArrayList;
public class ReadObjects {
public static void main(String[] args) {
System.out.println("Reading serialized list of arrays..");
try {
FileInputStream fs = new FileInputStream("people.ser");
ObjectInputStream os = new ObjectInputStream(fs);
// cast people as array of Person type..
Person[] people = (Person[])os.readObject();
@SuppressWarnings("unchecked")
ArrayList<Person> peopleList = (ArrayList<Person>) os.readObject();
int num = os.readInt();
for (int i = 0; i < num; i++) {
Person person = (Person) os.readObject();
System.out.println(person);
}
os.close();
} catch (IOException e) {
e.printStackTrace();
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
}
}