user2187875
user2187875

Reputation:

saving a file variable for use later?

I am working on a program for launching programs, and am using JFileChooser to let the user select the file, i would like the program to have the path of the last file available the next time the user starts my program, what would be the best way to accomplish this?

Upvotes: 0

Views: 802

Answers (2)

Mike M
Mike M

Reputation: 752

Use a properties file which acts similarly to a hashtable. This code should be pretty accurate (needs exception handling).

private void save(String _url){
    Properties prop = new Properties();
    prop.setProperty("url", _url);
    prop.store(new FileOutputStream("file.properties"), null);
}

private String open(){
    Properties prop = new Properties();
    prop.load(new FileInputStream("file.properties"));
    return prop.getProperty("url");
}

Upvotes: 2

KhAn SaAb
KhAn SaAb

Reputation: 5366

Either your program is web based then stored it in session, or write in file.

Upvotes: 0

Related Questions