Link to home
Start Free TrialLog in
Avatar of agrees
agrees

asked on

How to incoorperate a save.txt file into a JAR?

Hi all,

I have an application which I've put into a JAR archive so that I can distribute it.  But I have 1 file which I'm not sure what to do with.

It is a file which stores data when the application is closed, and reads it when the application is opened.  This is how I use it currently:

private static final String BASE_DIRECTORY = "C:/Documents and Settings/Administrator/jbproject/strategySimulator/src/images/";

BufferedReader in = new BufferedReader(new FileReader(BASE_DIRECTORY+ "strategies.txt"));

What is the best way to change this so that it works with a JAR file that I can distribute to people?  It can be within the JAR archive, or outside if that is better.
Avatar of zzynx
zzynx
Flag of Belgium image

I would create that file in the user's home directory
Avatar of expertmb
expertmb

outside the jar.
ASKER CERTIFIED SOLUTION
Avatar of zzynx
zzynx
Flag of Belgium image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
>> a file which stores data when the application is closed

If you store system preference and coficuration data in it, consider using the Preferences class
(http://java.sun.com/j2se/1.4.2/docs/api/java/util/prefs/Preferences.html)
e.g. On a windows machine it stores the preferences in the windows registry.
Avatar of agrees

ASKER

> If you store system preference and coficuration data in it

It's a list of user created objects (strategies) - a bit like saved game data.

> System.getProperties().getProperty("user.home");

The problem with this is that I want the save file to contain some default objects so that when the user first starts up the application there will be some data in the application the first time they load it up.

I can see a way to do this:  Check for the file and if it doesn't exist load in some default objects from program memory.  Is this the best thing to do?
>> I can see a way to do this:  Check for the file and if it doesn't exist load in some default objects from program memory.  
>> Is this the best thing to do?
Yes.

PS. If you use the Preferences method, you can specify a default value if not found
>> load in some default objects from program memory.
You mean simply some hard coded default objects
Avatar of agrees

ASKER

> You mean simply some hard coded default objects

yep.  Ok that's what I'll do, thanks for the help :)  
Thanks for accepting.
You're welcome.