The problem is that every time I execute the main method, the old content of a.xml is lost and is substituted with a new one. How to append content to the a.xml file without losing the previous information?
import java.io.FileNotFoundException;
import java.io.PrintWriter;
import com.thoughtworks.xstream.XStream;
import com.thoughtworks.xstream.io.xml.DomDriver;
public class Test {
public static void main(String[] args) throws FileNotFoundException {
XStream xs = new XStream(new DomDriver());
Foo f = new Foo(1, "booo", new Bar(42));
PrintWriter pw = new PrintWriter("a.xml");
xs.toXML(f,pw);
}
}
public class Bar {
public int id;
public Bar(int id) {
this.id = id;
}
}
public class Foo {
public int a;
public String b;
public Bar boo;
public Foo(int a, String b, Bar c) {
this.a = a;
this.b = b;
this.boo = c;
}
}