News for hackers. Stuff that matters.
Re:Lisp is Too Powerful by hmottestad on Saturday December 24, 2011 @12:11PM (#3389199)
One of my favorite things to do in java. Save anything to XML, it even handles all the objects your objects are pointing to. All you need to do is make your objects serializable. Then java handles everything else using reflection.

  public void saveAll(Object[] objects) {

	File file = new File(filename + ".xml");

	try {
		BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(file));
		XMLEncoder xenc = new XMLEncoder(bos);

		for (Object o : objects) {
			xenc.writeObject(o);
		}

		xenc.close();

	} catch (FileNotFoundException e) {
		System.err.println("File not found");
	} catch (IOException e) {
		System.err.println("Some other error");
	}
  }

There are no comments on this comment yet.