• 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
  • Tim Cooke
  • Ron McLeod
  • paul wheaton
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
  • Himai Minh
Bartenders:

how to deal with the property file that could be modified by user

 
Ranch Hand
Posts: 133
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,

I have a swing application which contains a property file. When the application start, it will read this file and get some info. Now this file is in the root directory within a jar file. And it works fine.

The problem is that when the jar file is given to a user, that user may want to change some info of the property file. It is not good to ask user to unzip the jar, change the file, and jar the files together, right?

Could I put the property file outside the jar file, and give it to user together with the jar file, then user can edit it conveniently, but how the application find this file in this case?

What is the professional way to deal with this problem?

Thanks for the help!
 
Rancher
Posts: 5119
38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What if your code allows for 2 property files. The one in the jar file would be the default if there isn't one in the folder with the jar file. Your program would write out a copy of the jar file on its first execution. Later it would test if there was a file in the folder and use it vs using the one in the jar.
 
Sheriff
Posts: 22854
132
Eclipse IDE Spring Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How about putting a copy in System.getProperty("user.home")? That's what most applications do. (Although on Windows, using the ApplicationData (Windows 2000 and XP) / AppData\Local (Windows Vista and 7) is a better location.) You can then first create a Properties object around the file in the JAR file, then use that as the parent for a Properties object around this user specific properties file.
 
david arnold
Ranch Hand
Posts: 133
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Got it, thank you Rob and Norm for your kind help! I will try to make it work as you guys advised.

Regards,
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic