This week's book giveaway is in the Jobs Discussion forum.
We're giving away four copies of Soft Skills and have John Sonmez on-line!
See this thread for details.
The moose likes Java in General and the fly likes Application Settings File Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Application Settings File" Watch "Application Settings File" New topic
Author

Application Settings File

Siamak Saarmann
Ranch Hand

Joined: Aug 21, 2004
Posts: 78
Hello,

I need to save/read settings of a software in an easy format (so that people can edit it using notepad if they want).

I had used properties files in web applications but now I am using J2SE to build a simple Swing App.

What can I use to save, read and update settings from inside my Java program?

Regards,
Mac


PhD Artificial Intelligence, OCJP1.6
Rahul Bhattacharjee
Ranch Hand

Joined: Nov 29, 2005
Posts: 2308
You can use properties in J2SE applications as well.Now the question is how can you pass the location of that property file.

You can use environment variable or pass it using the JVM argument , like :

java -DProp.location=c:\test.properties MyClass


Rahul Bhattacharjee
LinkedIn - Blog
Jeremy Botha
Ranch Hand

Joined: Feb 16, 2005
Posts: 125
A (perhaps better) file independent option would be to use the Preferences API.

Jeremy


McFinnigan? Never heard of him. Nobody here but us chickens...<br /> <br />SCJP for Java 1.4<br />SCJD for Java 5.0
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14428
    
  23

I don't know if the Preferences API is what you want. The way the preferences are stored using that API is platform-dependent. On Windows, it stores the preferences in the registry; that's hardly a place where you can easily edit them, and you can forget about editing them with Notepad.

The class java.util.Properties is part of J2SE. It's very easy to read and write configuration files using that class. Look it up in the API documentation.


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 8 API documentation
Jeremy Botha
Ranch Hand

Joined: Feb 16, 2005
Posts: 125
True, but if you're saving application config settings from inside an application, Preferences works just as well as Properties.

J
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14428
    
  23

Yes, but Siamak explicitly asked: "I need to save/read settings of a software in an easy format (so that people can edit it using notepad if they want)."
Rahul Bhattacharjee
Ranch Hand

Joined: Nov 29, 2005
Posts: 2308
Originally posted by Rahul Bhattacharjee:
You can use properties in J2SE applications as well.Now the question is how can you pass the location of that property file.

You can use environment variable or pass it using the JVM argument , like :

java -DProp.location=c:\test.properties MyClass


Have you evaluated the above option ?
Jeremy Botha
Ranch Hand

Joined: Feb 16, 2005
Posts: 125
Originally posted by Jesper Young:
Yes, but Siamak explicitly asked: "I need to save/read settings of a software in an easy format (so that people can edit it using notepad if they want)."


Whoops - missed that line

J
 
jQuery in Action, 2nd edition
 
subject: Application Settings File