user385261
user385261

Reputation: 4169

Is there an easy way to write a complex class' object into a file for java?

Suppose I have something like this:

class A
{
public B mem;
public int x;
public int y;
}

class B
{
public C mem1;
public D mem2;
}

class C
{
public Image img;
}

class D
{
public int m;
}


//Writing object A onto a file using ObjectWriter?

How would I write class A onto a file with ObjectWriter? If I directly write it, then it will only copy the pointer (if I am not mistaken).

Upvotes: 1

Views: 174

Answers (1)

Mike Thomsen
Mike Thomsen

Reputation: 37526

Yes. Use the serialization API. It's pretty dead simple.

Upvotes: 8

Related Questions