Dies ist mein saveTable
Knopf, der eine Zeile meiner Tabelle speichert und dann in meine Auto.auto
Datei legt, aber ich kann nur eine object(row)
von Auto type
speichern. Jedes Mal, wenn ich ein anderes line(row)
speichere, ersetzt es das alte mit dem neuen, so dass ich am Ende nur noch eine object(row of table)
in meiner Datei habe, nachdem ich 5 Mal auf die Schaltfläche "Speichern" geklickt habe, während mein Programm läuft. Wie kann ich das lösen? Wie füge ich meiner Datei jedes Mal mehr Objekte hinzu, wenn ich mein Programm starte?
saveTable.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
int row = Integer.parseInt(textField.getText());
getText.getAuto(row);
File tabel = new File("C:\\Users\\Jovan\\Desktop\\Auto.auto");
try {
if (!(tabel.exists())) {
tabel.createNewFile();
}
FileOutputStream fos = new FileOutputStream(tabel);
ObjectOutputStream oos1 = new ObjectOutputStream(fos);
oos1.writeObject(getText.getAuto(row));
oos1.close();
ObjectOutputStream os2 = new ObjectOutputStream(new FileOutputStream(tabel, true)) {
protected void writeStreamHeader() throws IOException {
reset();
}
};
os2.writeObject(getText.getAuto(row));
os2.close();
} catch (IOException error) {
error.printStackTrace();
}
}
});
Was ist 'fos'? Sollte es nicht 'new FileOutputStream (tabel, true);'? –