我正在开发一个用于启动程序的程序,并使用 JFileChooser 让用户选择文件,我希望程序在用户下次启动我的程序时具有最后一个可用文件的路径,什么会是实现这一目标的最佳方法吗?
最佳答案
使用与哈希表类似的属性文件。这段代码应该非常准确(需要异常处理)。
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");
}
关于java - 保存文件变量以供以后使用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20443181/