Sergey
Sergey

Reputation: 11908

Storing complex object to a file in android application

FileOutputStream fout = context.getApplicationContext()
                    .openFileOutput(FILENAME, Context.MODE_PRIVATE);
ObjectOutputStream out = new ObjectOutputStream(fout);
out.writeObject(complexObject);

Will this code work for a complexObject which is an instance of a complex class. By complex I mean that it might contain several arraylists of instances of other classes, many instance variables?

Upvotes: 0

Views: 566

Answers (1)

Peter Knego
Peter Knego

Reputation: 80340

Yes, ObjectOutputStream can serialize a complex tree of objects as long as all objects in this tree implement Serializable. It also serializes all java primitive types.

Upvotes: 1

Related Questions