• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Making the app config persistent

 
Michel Bertrand
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi !
I found an instruction in my assignment, URLyBird, to make the application configuration persistent among its executions. Probably to save the user preferences.
I did it using the java.util.Properties stored in a file on the user home directory, I mean by "user home directory" the .
What about it ? Is it a good approuch ? Would I have any problem running this in any OS's ?
Thank you very much !
Michel.
 
Flavio Nobili
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Michel,
The specification says:
Such configuration information must be stored in a file called suncertify.properties which must be located in the current working directory.

By "current working directory" I understand that it's the directory where the "runme.jar" is. So, you don't need to get the user directory from the system. Just give a FileOutputStream("suncertify.properties") to the store method, and it'll be stored in the current working directory.
Regards,
Flavio.
 
Michel Bertrand
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello !
It was my first approuch, but since I was unable to load the configuration when running the application from any directory, not the working directory, I could not get the suncertify.properties file. In the assignment I have instructions to start the application using "java -jar <path>/runme.jar <argument>". In this way, I intent that the user can start the application from any location.
So, how to get the absolute path to "suncertify.properties" starting the application out of the working directory ? Can anyone give me another tip ? As I told you before, I did not find any solution.
Thanks again !
Michel.
 
Philippe Maquet
Bartender
Posts: 1872
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Michel,
Instead of using System.getProperty("user.home"), you should use System.getProperty("user.dir").
If you look at the javadoc for System.getProperties(), you'll see that "user.dir" is what SUN means by "current working directory".
Regards,
Phil.
 
Michel Bertrand
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok, thanks guys ! It was a misunderstanding of my part. I have only to read the config file from the current application directory where the user starts it.
Regards,
Michel.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic