Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You may give it a try to the deefault XMLEncoder/XMLDecoder that was added to the platform in Java1.4</p> <p>Here's the way I use it.</p> <pre><code>import java.beans.XMLEncoder; import java.beans.XMLDecoder; import java.io.BufferedInputStream; import java.io.BufferedOutputStream; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; public class ToXml { /** * Write an object to a file in XML format. * @param o - The object to serialize. * @param file - The file where to write the object. */ public static void writeObject( Object o, String file ) { XMLEncoder e = null; try { e = new XMLEncoder( new BufferedOutputStream( new FileOutputStream(file))); e.writeObject(o); }catch( IOException ioe ) { throw new RuntimeException( ioe ); }finally{ if( e != null ) { e.close(); } } } /** * Read a xml serialized object from the specified file. * @param file - The file where the serialized xml version of the object is. * @return The object represented by the xmlfile. */ public static Object readObject( String file ){ XMLDecoder d = null; try { d = new XMLDecoder( new BufferedInputStream( new FileInputStream(file))); return d.readObject(); }catch( IOException ioe ) { throw new RuntimeException( ioe ); }finally{ if( d != null ) { d.close(); } } } </code></pre> <p>}</p> <p>It's easy, is simple, is in the core libraries. </p> <p>You just have to write the load mechanism. </p> <p>I have this swing app that loads data from a remote EJB in 5 - 10 secs. What I do is to store the previous session in XML like this and when the app loads it has all the data from the previous session in less than 1 sec. </p> <p>While the user start to work with the app, a background thread fetches those elements that have changed since the last session. </p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload