Strona 1 z 1

Zapisywanie obiektów do pliku

Napisane: wtorek, 7 sierpnia 2012, 20:28
przez ducek
Witam!

taki kod zapisuje obiekt do pliku


ObjectOutputStream zapis = new ObjectOutputStream(new FileOutputStream("baza.txt"));

zapis.writeObject(os);

zapis.close();

Czy można dopisać do pliku kolejny obiekt ? może istnieje jakaś metoda typu append?

Pozdrawiam!

Re: Zapisywanie obiektów do pliku

Napisane: środa, 8 sierpnia 2012, 19:26
przez Morfidon
The method writeObject is used to write an object to the stream. Any object, including Strings and arrays, is written with writeObject. Multiple objects or primitives can be written to the stream. The objects must be read back from the corresponding ObjectInputstream with the same types and in the same order as they were written.
źródło

Po prostu korzysta się ponownie z metody writeObject