0

I am working on a game and eventually I would like to have it be able to save control schemes so the user does not have to change it every time, and save stats and things like that. I know an easy way of doing it which is writing to a text file and then reading that, but I have no idea how it would work once the project is packed into a jar/exe for distribution. If anyone knows the best way of doing this, that'd be great!

Miles
  • 487
  • 3
  • 12
  • Why not allow the user to save their configuration in-game and ask them for the path to save it on? Alternately, why not save it in the path where the game gets installed by default? Why does it need to be bundled in the jar? – Chetan Kinger Mar 06 '15 at 15:35
  • You can put a folder in the same path as the JAR and load from there. Then the whole thing would be your game. – CaffeineToCode Mar 06 '15 at 15:39
  • As @CaffeineToCode mentioned, you'd store the file within your *source* folder (in the `src` folder), then use [`getResource(String)`](http://docs.oracle.com/javase/8/docs/api/java/lang/Class.html#getResource-java.lang.String-). Check out [this example](http://stackoverflow.com/questions/2593154/get-a-resource-using-getresource) – Vince Mar 06 '15 at 16:11

1 Answers1

0

When your JAR is packaged, create a folder in your src folder with the files. Then use getResource(path) to access the files. If you don't wan't the files as part of the JAR, make another src folder and put the files in there, using the same method. Then, after you make the JAR, you will place a copy of the src folder with the resources in a folder with the JAR, and there's your game. The easiest way is to ZIP the finished package up, and have the user unzip it.

If you used the second method the ZIP would look something like this:

Game.zip (The contents of this would usually go in Program Files)
|
+--- GameExecutable.jar (Your executable JAR file)
|
+--- resources (Folder)
|    |
|    +--- Image.png
|    |
|    +--- Image2.png
|
+--- config (folder)
     |
     +--- User1.config (Basic text file, holds configuration settings)
CaffeineToCode
  • 830
  • 3
  • 13
  • 25