Java Reference
In-Depth Information
L ISTING 6.2
StudentListApplication.java
import java.io.*;
public class StudentListApplication {
// Default Constructor
public StudentListApplication() {
}
// Adds Student Names to List
public void buildStudentList(StudentList value) {
value.addStudent(“Bob Robinson”);
value.addStudent(“Steve Bobinson”);
value.addStudent(“Rob Stevinson”);
value.addStudent(“Todd Thompson”);
value.addStudent(“Tom Toddson”);
value.addStudent(“Rob Bobinson”);
}
// Stores the Serializable StudentList to the file “file.dat”
public void putStudentList(StudentList value) {
try {
// Create the ObjectOutputStream passing it the
// FileOutputStream object that points to our
// persistent storage.
ObjectOutputStream os = new ObjectOutputStream(
new FileOutputStream(“file.dat”));
// Write the StudentList to the ObjectOutputStream
os.writeObject(value);
os.flush();
os.close();
}
catch (IOException e) {
System.err.println(e.getMessage());
}
}
public StudentList getStudentList() {
StudentList list = null;
Search WWH ::




Custom Search