jQuery in Action, 2nd edition
The moose likes Java in General and the fly likes how to deal with the property file that could be modified by user Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Java in General
Reply Bookmark "how to deal with the property file that could be modified by user" Watch "how to deal with the property file that could be modified by user" New topic
Author

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

david arnold
Ranch Hand

Joined: Apr 10, 2009
Posts: 129
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!
Norm Radder
Ranch Hand

Joined: Aug 10, 2005
Posts: 681
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.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19216

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.


SCJP 1.4 - SCJP 6 - SCWCD 5
How To Ask Questions How To Answer Questions
david arnold
Ranch Hand

Joined: Apr 10, 2009
Posts: 129
Got it, thank you Rob and Norm for your kind help! I will try to make it work as you guys advised.

Regards,
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: how to deal with the property file that could be modified by user
 
Similar Threads
build problems and relative paths
I am close to submit - quetions
Jar a project with property files in it external to jar
Run a java program when the OS loads
JAR - SWING - based problem