• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How to edit text file in jar

 
Ranch Hand
Posts: 268
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all.
I have a small swing application which edits the text file. I want to keep that text file inside the application jar file. N edit when ever required. Is this possible??? If yes, please help me a little.



Thanks & Regards
Adeeb.
 
Ranch Hand
Posts: 129
1
Oracle Opera Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Why do you need to keep the text file inside a jar. You can directly use it from the environment where you have your appln . Could you briefly elaborate & it would be helpful for others if you post the Code.
 
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can certainly extract the file from the jar, but it really isn't practical to try to update the jar. To do that requires rebuilding the jar, which is going to be very inconvenient.

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.

 
adeeb alexander
Ranch Hand
Posts: 268
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.


Thanks.
 
Bartender
Posts: 11497
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If your application is a distributed application, the best way to store this information is on the server. Then you can get it and use it, irrespective of which machine the client uses.

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?
 
Sheriff
Posts: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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"?
 
Paul Clapham
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.



N?

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.
 
adeeb alexander
Ranch Hand
Posts: 268
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry, i am habituated with that language because i use yahoo all the time. Anyway, thank you all for your help.


Bye.
 
No more fooling around. Read this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic