0

Possible Duplicate:
How do I access a config file inside the jar?

First of all I give you a sample of my code, then I ask what I intend to do :

public static void resetGlobalConfigFile() throws IOException{

        File f=new File("appconfig.conf");

        FileWriter fWritter = new FileWriter(f);
        BufferedWriter bWritter = new BufferedWriter(fWritter);

        bWritter.write("# Path to the campaigns config file (xml)\r\n");
        bWritter.write("campaigns_xml_file=./campaigns/campaigns.xml");

        bWritter.close();

        f.createNewFile();
    }

In fact when I distribut my jar, there is a config file with it (appconfig.conf).

In my code I have done the resetGlobalConfigFile() method for allow the user to reset this config file with the default values.

But I think It would be better to store a default config file (for example embedded in my .jar;is it possible ?) that I can easyly manage with my favorite text editor (while developpement stage). When application is compiled nobody could edit the default config file.

But I dont know how to do it ? Maybe you have any other solution ? Because the real goal is to can write this default file with a text editor (in developemment stage) and nobody can change the default values when compiled (production stage) !

Thaks for reading.

Community
  • 1
  • 1
troc
  • 379
  • 2
  • 4
  • 16
  • @Frank van Puffelen Thanks to your link I found [`java.util.prefs.Preferences`](http://docs.oracle.com/javase/6/docs/api/java/util/prefs/Preferences.html). Do you think it is the best solution in my case ? – troc Dec 03 '12 at 23:31
  • The best solution is the one that works. So if the `Preferences` class works for you, go for it. But keep in mind that Stack Overflow is meant for questions that have a single clear answer. Questions like "what is the best...?" typically lead to debate, for which Stack Overflow is not the best site. – Frank van Puffelen Dec 03 '12 at 23:34

0 Answers0