So far I have seen that I can save them via these:
- The Preferences class - I like it but it requires admin rights in windows for the registry editing
- The Properties class - This seems that it is useful for storing data. I also saw that I can load a file from the jar like this:
inputStream = Main.class.getResourceAsStream("config.properties");
however - once I load it I ( please correct me if I am wrong ) CANNOT edit it. Editing text file inside the jar programmatically is not possible. Instead I should just save it to the same directory as the .jar using this:
File newFile = new File("config.properties");
OutputStream os = new FileOutputStream(newFile);
properties.store(os, "Properties File");
as long as the file is where the class called Main is.
- The third way is basically the same as the second but while loading from hard coded default values instead loading from txt file.
Please tell me if you know another way of loading settings in a program. And please clarify this - basically the only way the user doesn't get a pesky file next to his jar for saving properties is for me to use Preferences. Of course taking under consideration that we can't have absolute paths seeing as different operating systems will be a problem.
System.getenv("APPDATA")) or inside the user home on Unix-based systems (System.getProperty("user.home"), or~/if the home property is null). You may want to create a method that detects if the operating system is Windows and returns the data directory path appropriately.