I/O using XML in Java.

Soldato
Joined
23 Dec 2010
Posts
3,483
Hey guys,

We've been asked to create a application which utalises 3 kinds of IO, text, XML and serialization.

Text and Serialization went by without any hitches, but for some reason XML refuses to work.

Quick overview of the application here.


  • Two classes, books and authors.
  • Linked by the author instance variable.
  • Method class with all of the methods inside (who would have guessed?)

This is what I've got.

Going to the method -

Code:
try {
                   writeXML("file.xml");
                }
                catch (IOException e) {
                    System.out.println("Error whilst writing file");
                }
            }
The method itself

Code:
public void writeXML(String fn) throws IOException {
        XMLEncoder encoder = new XMLEncoder(new BufferedOutputStream(
                new BufferedOutputStream(
                        new FileOutputStream(fn))));
        encoder.writeObject(this);
        encoder.close();
    }

I can't see anything wrong there, can you?

Edit:- Important to note that the ArrayList with the book and author objects stored is also in this class - hense the (this).
 
Last edited:
Back
Top Bottom