Java Reference
In-Depth Information
L ISTING 6.2
Continued
try {
System.out.println(“\n Press enter to quit.”);
System.in.read();
}
catch (Exception e) {
System.err.println(e.getMessage());
}
}
public static void main(String[] args) {
StudentListApplication studentListApplication =
new StudentListApplication();
studentListApplication.invoke();
}
}
You need to look at two sections of the StudentListApplication . The first is the
putStudentList() method in which the StudentList object is written to the file file.dat .
This method is listed as follows:
// 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());
}
}
Search WWH ::




Custom Search