String filepath;
chooser.showOpenDialog(this);
filepath = chooser.getSelectedFile().getPath();
如何保存文件路径
?
因为下次运行项目时,我想自动打开该文件,但 filepath
总是再次设置为 ""
。
我不想设置filepath
的特定路径,因为它取决于用户。
提前致谢。
最佳答案
您可以使用 Java 的 Preferences API,这就是它的目的:
Preferences node = Preferences.userRoot().node("MyApp");
// store the file path
node.put("filepath", filepath);
// retrieve the file path
filepath = node.get("filepath", "");
关于java - 如何保存所选文件路径以供下次运行项目时使用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50802004/