Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Application Settings File

 
Siamak Saarmann
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Rahul Bhattacharjee
Ranch Hand
Posts: 2308
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Jeremy Botha
Ranch Hand
Posts: 125
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A (perhaps better) file independent option would be to use the Preferences API.

Jeremy
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Posts: 15359
39
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Jeremy Botha
Ranch Hand
Posts: 125
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 15359
39
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2308
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 125
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic