我已经使用包含Employees数据的文本文件创建了一个序列化文件,例如他们的姓名和员工编号等。
现在我想用我制作的序列化文件中的数据填充我的JTextFields。我该如何采取这一步骤?
这是我的代码:
import java.io.*;
public class CreateCustomerSer
{
public static void main(String args[]) {
Customer cust;
try
{
ObjectOutputStream output = new ObjectOutputStream( new FileOutputStream("customer.ser"));
output.writeObject(new Customer(100, "Estelle", "Zietsman", "Bellville", false));
output.writeObject(new Customer(200, "Karin", "Swart", "Welgemoed", true));
output.writeObject(new Customer(300, "Kruben", "Naidoo", "Sea Point", true));
output.writeObject(new Customer(400, "Wilhelm", "Rothman", "Manenberg", true));
output.writeObject(new Customer(500, "Gillian", "Khan", "Bellville", true));
output.writeObject(new Customer(600, "Denise", "Lakay", "Bishops court", false));
output.close();
ObjectInputStream input = new ObjectInputStream(new FileInputStream("customer.ser"));
while (true) {
cust = (Customer) input.readObject();
System.out.println(cust.toString());
}
}
catch(EOFException fnfe )
{
return;
}
catch(IOException fnfe )
{
System.out.println(fnfe);
System.exit(1);
}
catch(ClassNotFoundException fnfe )
{
System.out.println(fnfe);
System.exit(1);
}
}
}