이것은 내 saveTable
버튼으로 내 테이블의 한 행을 저장하고 내 Auto.auto
파일에 저장하지만, object(row)
은 Auto type
중 하나만 저장할 수 있습니다. 때마다 나는 다른 line(row)
저장할 때마다 내 새 프로그램을 실행하는 동안 5 번처럼 저장 버튼을 클릭 한 후 내 파일에 object(row of table)
하나만 가지고 그래서 그것은 새로운 한 whith 오래 된 하나를 대체합니다. 이 문제를 어떻게 해결할 수 있습니까?내 프로그램을 실행할 때마다 내 파일에 개체를 추가하는 방법은 무엇입니까?
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();
}
}
});
무엇에 대해'fos'? 그것은'new FileOutputStream (tabel, true);이 아니어야합니까? –