• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

Making the app config persistent

 
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Bartender
Posts: 1872
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic