Jump to content

Check out our Community Blogs

Register and join over 40,000 other developers!

Recent Status Updates

View All Updates

- - - - -

Useing Properties files within a jar

java jar config configuration properties file

This topic has been archived. This means that you cannot reply to this topic.
1 reply to this topic

#1 JoeKing612


    CC Newcomer

  • Member
  • PipPip
  • 12 posts

Posted 07 June 2013 - 10:04 PM

In a game I am making in java I need to save and load information from a Properties file that is all within a jar file. I can acomplish this outside of a jar file via the folowing code:

//save info

               Properties prop = new Properties();

                try {
    		//set the properties value
    		prop.setProperty("speed", Integer.toString(playerSpeed.getValue()));
    		//save properties to project root folder
    		prop.store(new FileOutputStream("/Config/options.properties"), "The Options...");
    	} catch (IOException ex) {

//Load info

                try {
			prop.load(new FileInputStream("/Config/options.properties"));
		} catch (Exception e) {
		playerSpeed = new JSlider(JSlider.HORIZONTAL, -30, 30, Integer.valueOf(prop.getProperty("speed")).intValue());

but this only works inside a jar if the Config directory is outside the jar, and I want the Config directory to be inside the jar.


please help!

Edited by JoeKing612, 07 June 2013 - 10:06 PM.

#2 BlackRabbit


    CodeCall Legend

  • Expert Member
  • PipPipPipPipPipPipPipPip
  • 3871 posts

Posted 10 June 2013 - 10:27 PM

It's not possible to save data into a runnable jar file ( well... impossible... let's say out of the reach by conventional means)


For what you need you should rather use java.util.preferences

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download