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/jbp roject/str ategySimul ator/src/i mages/";
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.
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/jbp
BufferedReader in = new BufferedReader(new FileReader(BASE_DIRECTORY+
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.
I would create that file in the user's home directory
outside the jar.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
>> 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.
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.
See http://javaalmanac.com/egs/java.util.prefs/BasicGetSet.html for the simple use of it
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().get Property(" 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?
It's a list of user created objects (strategies) - a bit like saved game data.
> System.getProperties().get
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
>> 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
You mean simply some hard coded default objects
ASKER
> You mean simply some hard coded default objects
yep. Ok that's what I'll do, thanks for the help :)
yep. Ok that's what I'll do, thanks for the help :)
Thanks for accepting.
You're welcome.
You're welcome.