如何在不打开文件对话框的情况下检测jnlp中是否存在文件?

发布于 2024-08-21 09:15:38 字数 573 浏览 3 评论 0原文

在我的 jnlp 应用程序中,我需要知道用户属性文件是否存在,如果存在,则加载它,我的代码如下所示:

File_Contents=File_Open_Service.openFileDialog(".",new String[]{".txt"});
String Text=readFromFile(File_Contents);

InputStreamReader in=new InputStreamReader(File_Contents.getInputStream());
Application_Props.load(in);

用户不知道属性文件的名称,所以即使我打开一个对话框,他们也会不知道要选择哪个文件,所以我的问题是:在 jnlp 中我可以做类似的事情: if (new File("abc.txt").exists) Load_Property() 吗?如果不存在,继续,不弹出对话框,如果存在,也不需要打开对话框,直接读入,如果需要,询问用户是否可以读入文件命名为“abc.txt”作为属性文件。如何在 jnlp 中实现这一点?有示例代码吗?

PS:我没有在“所有权限”模式下运行它,因为这需要第三方证书。这花了一点钱。

In my jnlp app I need to know if a user property file exists, if it does, load it, my code looks like this :

File_Contents=File_Open_Service.openFileDialog(".",new String[]{".txt"});
String Text=readFromFile(File_Contents);

InputStreamReader in=new InputStreamReader(File_Contents.getInputStream());
Application_Props.load(in);

Users don't know the name of the property file, so even if I open a dialog box, they won't know which file to choose, so my question is : in jnlp can I do something like : if (new File("abc.txt").exists) Load_Property() ? If it doesn't exist, go on without popping up a dialog box, if it exists, don't need to open a dialog box either, just read it in, if necessary, ask the user if it's ok to read in a file named "abc.txt" as a property file. How to achieve this in jnlp ? Any sample code ?

PS : I'm not running it in "all-permissions" mode, because that requires a 3rd party cert. which cost a bit.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

拥醉 2024-08-28 09:15:38

好吧,我已经弄清楚如何实现这一点:使用 PersistenceService。
我可以借助 JNLP 的 PersistenceService 将用户设置保存到 html 中的 cookie 之类的内容中,并在下次加载它,而无需每次都打开对话框。

我可以轻松检测它是否存在,而无需询问用户。

Alright, I've figured out how to achieve this : use the PersistenceService.
I can save the user setting into something like a cookie in html with the help of JNLP's PersistenceService, and load it next time without the need to open a dialog box every time.

I can easily detect if it exists or not without asking users.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文