Let's suppose that this file is the configuration file for your application, and you want to allow the user to modify the configuration. The way to do that is to store the modified configuration in the user's directory. Then to find the configuration file you first look in the user's directory; if it isn't there then you get it from the jar.
You can find the user's directory by looking at the "user.home" system property.
In case of stand alone applications, ask yourself this question:
Suppose you configure your machine with a particular wallpaper. Would you expect the same wallpaper on a different machine?
adeeb alexander wrote:N
karthik Suryanarayanan wrote:appln
adeeb alexander wrote:N ... N ... n ... n ... ma
Can you two please UseRealWords? Especially Adeeb; is it so hard to write "and" and "my"?
adeeb alexander wrote:Thanks a lot for replying. The application just stores the info in text file. Suppose i want to use the application on other system. Then i should even copy the text file. N there will be not enough security. N also if user forget to copy the text file, n just take the jar n start to use on other system, he will miss tht previous info. Is there any way to achieve ma requirement.
Anyway those are all pretty lame excuses. Especially the one about security, since the file is just as easily seen in the jar as in somebody's directory. And the one about where the user forgot to copy over the configuration? Not hard to fix that, really. Copy it over when you find out you forgot.
You could of course put something in place where when the user modifies the configuration, you do this:
(1) Create a new copy of the jar file containing the new configuration and everything else which was in the original jar.
(2) Terminate the application.
(3) Delete the old jar and rename the new jar to be the old jar.
(4) Start the application again.
Of course that would be inconvenient (as I said already), but if you really wanted to do that instead of doing it the simple and straightforward way, then yes, you could certainly do that.
It's worth mentioning that most -- almost all -- applications don't preserve the old configuration when they are reinstalled on a new system, and in a lot of cases you wouldn't want to do that.