gpt4 book ai didi

java - 如何保存所选文件路径以供下次运行项目时使用?

转载 作者:行者123 更新时间:2023-12-02 11:07:53 25 4
gpt4 key购买 nike

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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com