loading and saving
I use “muffins” 
They are like cookies but for webstart. Well, they are somewhat odd to handle and there aren’t many examples on the net (the most useful site was actually written in korean ::)).
One of the annoying pitfalls is that you can’t overwrite a muffin, which leads to a somewhat odd try/catch structure. Eg you need to delete it each time, but there won’t be one on the first run.
I also added a nice method called showURL… it starts the client’s default browser with the specified url as parameter.
import javax.jnlp.*; //you need the webstart toolkit
import java.net.*;
import java.io.*;
[...]
public boolean showURL(URL url) //this one is pretty nice, too
{
try
{
BasicService bs = (BasicService)ServiceManager.lookup("javax.jnlp.BasicService");
return bs.showDocument(url);
}
catch(UnavailableServiceException ue)
{
return false;
}
}
public void writeConfig()
{
PersistenceService ps;
BasicService bs;
URL configURL;
try
{
ps = (PersistenceService)ServiceManager.lookup("javax.jnlp.PersistenceService");
bs = (BasicService)ServiceManager.lookup("javax.jnlp.BasicService");
URL baseURL = bs.getCodeBase();
System.out.println("CodeBase was " + baseURL);
configURL = new URL(baseURL, "config");
}
catch(Exception e)
{
System.out.println("[E]failed to save configuration");
return;
}
try
{
ps.delete(configURL);
}
catch(Exception e)
{
System.out.println("there wasn't a muffin - first save");
}
try
{
ps.create(configURL, 1024); //1024 bytes for our data
FileContents fc = ps.get(configURL);
DataOutputStream os = new DataOutputStream(fc.getOutputStream(false));
os.write[...whatever...]
os.flush();
os.close();
System.out.println("saved configuration");
}
catch(Exception e)
{
System.out.println("[L]failed to save configuration");
e.printStackTrace();
}
}
public void readConfig()
{
try
{
PersistenceService ps = (PersistenceService)ServiceManager.lookup("javax.jnlp.PersistenceService");
BasicService bs = (BasicService)ServiceManager.lookup("javax.jnlp.BasicService");
URL baseURL = bs.getCodeBase();
URL configURL = new URL(baseURL, "config");
FileContents fc = ps.get(configURL);
DataInputStream in = new DataInputStream(fc.getInputStream());
in.read[...whatever...];
in.close();
}
catch (Exception e)
{
System.out.println("unable to load settings");
}
}
[...]
The muffin location on win9x is here:
<userdata>\Sun\Java\Deployment\javaws\cache\muffins
(and my program seems to be the only one which uses muffins)
Well, you can’t save as much data as you like to. There are some limits and you can gently ask for some more room… haven’t grasped the whole concept since the documentation is somewhat fuzzy there.
However, the good thing is that you won’t need any permissions for the stuff above.