Skip to main content
GameDev.net gamedev.net
🔒 Locked

[java] Store program settings

Started by Amarth Oct 29, 2006 at 5:26 PM 3 replies 1.1k views
Original Post
Amarth
Amarth
A bit inspired by another thread out there (Why do some games need admin accounts?), where and how should you write settings for a Java game? We are currently developing a (non-applet) Java game. The idea is that it shouldn't matter too much for the end user, and we're probably going to distribute it for Windows with installer and everything. However, I want to keep the option of distributing it to other platforms open, and I wondered if there is a way of knowing in Java where you're allowed to write settings for your application. The idea is that, with Java, you don't need to know what OS you're running on, so, is there somewhere some abstraction to remove the difference between a "\Documents and settings\user\" and a "/home/user/"? Thanks, -Amarth
Michael Nischt
Michael Nischt
You could use:
System.getProperty("user.home");

It not only returns a path independent of the OS,
(e.g.: Win2k/XP: C:\Documents and settings\%user%\, MacOSX/Users/%user%/, UNIX/LINUX: /home/%user%/)

but also with regard to its language settings.
(e.g.: English: C:\Documents and settings\%user%\, German: C:\Dokumente und Einstallungen\%user%\)
Amarth
Amarth
Sweet, exactly what I was looking for. Thanks!
CaptainJester
CaptainJester
Even better is the preferences API.

java.util.prefs.*

On Windows, this will store settings in the registry. It works on other platforms, but I am not sure where they are stored.
"None of us learn in a vacuum; we all stand on the shoulders of giants such as Wirth and Knuth and thousands of others. Lend your shoulders to building the future!" - Michael Abrash[JavaGaming.org][The Java Tutorial][Slick][LWJGL][

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.