Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

NX: URLyBird 1.3.3 -- Problem on read/write suncertify.properties

 
kwwong wong
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How to store the configuration information in the suncertify.properties. Is it use the Properties class ? If yes, how to specify the properties file is suncertify.properties and location at current directory when create Properties Object? Is it use getProperty/setPropertyto read/store the properties ?
Thanks.
 
Andrew Monkhouse
author and jackaroo
Marshal Commander
Pie
Posts: 12014
220
C++ Firefox Browser IntelliJ IDE Java Mac Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi kwwong
Yes, use the Properties class. And to specify the location, you could use the System.getProperty("user.dir") to find the current working directory.
Regards, Andrew
 
kwwong wong
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Andrew,
Thanks. The problem of read/store properties is solved. The following line is stored in suncertity.properties.
databaseLocation=C\:\\kwwong\\db-1x3.db
If I summit the assignment with this properties file, the examiner will update the filepath for data file, is it O.K. ?
Should I handle the path-separator on Win/Unix system ? Or let the user set the databaseLocation on the first time the application running ?
Thanks
 
Andrew Monkhouse
author and jackaroo
Marshal Commander
Pie
Posts: 12014
220
C++ Firefox Browser IntelliJ IDE Java Mac Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi kwwong
I would not submit anything to Sun that has a local path in it.
I would recommend not shipping any properties file - generate one when the user first starts the application. Prompt them for the location of the database etc., then store the data in the newly created properties file. Then every time after that, the properties file can be read to see the last defined information.
If you want to go the extra mile, you could try and work out where the database is likely to be (it might be in the current working directory or it might be in the same directory as the jar file) and then you can offer the found location as a default to the assessor. I found this very easy to do, and it is a nice feature, but not essential.
Regards, Andrew
 
Philippe Maquet
Bartender
Posts: 1872
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Kwwong,
Be aware that we must handle the fact that we have one properties file shared by 3 applications (server, client, stand-alone) if we run them on the same machine.
So we should put a locking mechanism in place. Conceptually, loading and saving properties mean :
Loading:
-------


Saving:
------

In another thread, Andrew proposed a nice way to perform the lock based on creating a temporary file. It seems perfect.
Regards,
Phil.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic