Saving Preferences from within a JAR
<p>I am currently writing a game, and have come to the point where I need the user to be able to save preferences for things such as the JFrame size, key bindings etc. The users will be running the game through a jar downloaded from my website. </p>

<p>I've decided to go with the Preferences API under "java.util.prefs.Preferences". I am still quite new when it comes to reading things like documentation, and would like someone to help explain a bit to me.</p>

<p>So far, I have something like this:</p>

<pre><code>Preferences prefs = Preferences.userNodeForPackage(com.custardgames.horde2d.Game.class);
prefs.put(name, value);
</code></pre>

<p>Now then, how do I actually get to saving the preference file on the users computer? Right now, if I run the program again and try just:</p>

<pre><code>Preferences prefs = Preferences.userNodeForPackage(com.custardgames.horde2d.Game.class);
System.out.println(prefs.get(name, null));
</code></pre>

<p>It just returns null which is the default value if there is nothing saved. I know I am missing the vital part of actually saving the file, and then opening it the correct way, but haven't gotten much out of googling it. </p>

<p>Thanks so much in advance!</p>

<p>Edit:
FYI, for reading images, I am using something like this:</p>

<pre><code>BufferedImage currentImage=ImageIO.read(this.getClass().getClassLoader().getResource("res/images/image.jpg"));
</code></pre>

<p>I would like to be able to do something similar with preferences.</p>

<p>Edit:
<code>name</code> and <code>value</code> are both String variables declared beforehand.</p>
