I'm writing a func with ObjectOutputStream and ObjectInputStream to import and export contact information into a file.
I have a exception java.io.StreamCorruptedException: invalid stream header: EFBBBFAC in part ObjectInputStream and I don't know fix it.
How to fix it, Thank you.
LienHe lh = new LienHe(name, phone, img);
try {
ObjectOutputStream out = new ObjectOutputStream(
new FileOutputStream("src/Bai6/lienhe.txt", true));
out.writeObject(lh);
out.close();
} catch (FileNotFoundException ex) {
Logger.getLogger(FrmThemLienHe.class.getName()).log(Level.SEVERE, null, ex);
} catch (IOException ex) {
Logger.getLogger(FrmThemLienHe.class.getName()).log(Level.SEVERE, null, ex);
}
lst = new ArrayList<>();
try {// exception
ObjectInputStream in = new ObjectInputStream(
new FileInputStream("src/Bai6/lienhe.txt")));
while (in.available() > 0) {
LienHe lh = (LienHe) in.readObject();
lst.add(lh);
}
} catch (ClassNotFoundException | IOException ex) {
System.out.println(ex.getMessage());
}