This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan 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 Android Security Essentials Live Lessons this week in the Android 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: 77
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 Candidate: Distributed and Parallel Systems, Simulation and Modeling
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: 14074
    
  16

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 7 API documentation
Scala Notes - My blog about Scala
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: 14074
    
  16

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
 
wood burning stoves
 
subject: Application Settings File
 
Similar Threads
Basic question with Eclipse
Reading and Writing files using Java Script
Populating dynamically from XML file
IDEA 4: Export Code Formatter Settings
Generate JSP based on template