Java Reference
In-Depth Information
new ObjectInputStream(
new FileInputStream("personnelList.dat"));
int staffCount = 0;
try
{
staffListIn =
(ArrayList<Personnel>)inStream.readObject();
//The compiler will issue a warning for the
//above line, but ignore this!
for (Personnel person:staffListIn)
{
staffCount++;
System.out.println(
"\nStaff member " + staffCount);
System.out.println("Payroll number: "
+ person.getPayNum());
System.out.println("Surname: "
+ person.getSurname());
System.out.println("First names: "
+ person.getFirstNames());
}
System.out.println("\n");
}
catch (EOFException eofEx)
{
System.out.println(
"\n\n*** End of fi le ***\n");
inStream.close();
}
}
}
class Personnel implements Serializable
{
private long payrollNum;
private String surname;
private String fi rstNames;
public Personnel(long payNum,String sName,
String fNames)
{
payrollNum = payNum;
surname = sName;
fi rstNames = fNames;
}
Search WWH ::




Custom Search