Using XMLEncoder to persist PlainDocument
- From: Dave Neuendorf <dwn@xxxxxxxxxxxxx>
- Date: Fri, 28 Oct 2005 16:23:18 -0400
I'm trying to use XMLEncoder for the first time. My need is to persist a PlainDocument to a file. Here is the code I'm using to do this:
ContentDocument content = ...; // where ContentDocument extends PlainDocument and gets initialized with some text
File file = new File( filename );
try
{
FileOutputStream fileOut = new FileOutputStream( file );
XMLEncoder e = new XMLEncoder( new BufferedOutputStream( fileOut ) );
e.writeObject( content );
e.close();
}
catch ( IOException ex )
{
JOptionPane.showMessageDialog( null, "Unable to save content:\n" + ex.getMessage() );
}
In my debugger, I've confirmed that the ContentDocument instance called "content" indeed contains some text.
When I open the file that is produced, here is what is in it:
<?xml version="1.0" encoding="UTF-8"?> <java version="1.5.0_04" class="java.beans.XMLDecoder"> <object class="com.neusys.hierarchicalpim.ContentDocument"/> </java>
Clearly the text has not been included in what has been persisted. What am I doing wrong?
Thanks, Dave Neuendorf .
- Follow-Ups:
- Re: Using XMLEncoder to persist PlainDocument
- From: Roedy Green
- Re: Using XMLEncoder to persist PlainDocument
- Prev by Date: Re: can JTree's have multiple roots and models ?
- Next by Date: Re: Using XMLEncoder to persist PlainDocument
- Previous by thread: How to size a JTextField according to a fixed string length?
- Next by thread: Re: Using XMLEncoder to persist PlainDocument
- Index(es):