tags:

views:

50

answers:

1

I am trying to make an application launcher that has a settings file that will save 'names' for programs and the path to that program, and when you type the name in an input box it will run the program that name is assigned to.

Also if it the name entered is not known by the application (in the settings file) it will ask the user to add the path and will save that name with the user set path in the settings file.

What I need to know is the best way for me to do this and read/write the file, and the easiest way to organize the settings file to be interpreted.

Any suggestions?

+4  A: 

You could use java.util.Properties - it stores key/value pairs in a textfile, and is fairly easy to instantiate. e.g:

Properties mySettings = new Properties();
mySettings.load(new FileInputStream("myapp.cfg"));

// getProperty() returns a String
filepath1 = mySettings.getProperty("filePath1");

Then you simply save your settings in myapp.cfg, either directly (it's a simple textfile with key=value pairs), or via mySettings.store(...). The contents of myapp.cfg will look something like this:

# comment and date added by the Properties object
filePath1=/usr/bin/share/filename
otherVar=52
Jeremy Smyth