有人可以帮我做到这一点吗?
我无法反序列化。我怎样才能反序列化这个程序?
项目清单
public static void main(String[] args) {
contato acon [] = new contato[3];
acon [0] = new contato();
acon [0].setName("joyce");
acon [0].setAddress("hileia n° 587");
acon [0].setFone("789-456");
acon [1] = new contato();
acon [1].setName("naldo");
acon [1].setAddress("bairro da paz n°15821");
acon [1].setFone("654-123");
acon [2] = new contato();
acon [2].setName("jessica");
acon [2].setAddress("cidade nova n°15");
acon [2].setFone("456-789");
try {
FileOutputStream fs = new FileOutputStream("contato.ser");
ObjectOutputStream os = new ObjectOutputStream(fs);
os.writeObject(acon);
os.close();
} catch (Exception ex) {
ex.printStackTrace();
}
try {
FileInputStream fs = new FileInputStream("contato.ser");
ObjectInputStream oi = new ObjectInputStream(fs);
System.out.println(oi.readObject());
oi.close();
fs.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}
反序列化此对象时总是出错。
public class contato implements Serializable {
private String name;
private String address;
private String fone;
public void setName(String name) {
this.name = name;
}
public void setAddress(String address) {
this.address = address;
}
public void setFone(String fone) {
this.fone = fone;
}
public String getName() {
return name;
}
public String getAddress() {
return address;
}
public String getFone() {
return fone;
}