gpt4 book ai didi

java - 如何在启动时向我的 java 应用程序(如 .exe)传递文档的路径?

转载 作者:行者123 更新时间:2023-12-02 06:00:43 28 4
gpt4 key购买 nike

我使用 JSmooth 将我的 java 应用程序 (jar) 转换为可执行文件。这是一个简单的文本编辑器,就像记事本一样。我想使用Windows的“打开方式”功能来用exe打开某些文件。为此,我只需要每个文件的路径。我该怎么做?

我考虑过使用 java-property 并使用 System.getProperty("VariableName") 调用它,尽管我不知道这是否可行。 ${EXECUTABLEPATH} 只是获取 MyApp.exe 的位置。

最佳答案

对于简短的属性可以使用 Preferences.userNodeForPackage(MyExample.class);和方法:get、put、flush。
https://docs.oracle.com/javase/8/docs/technotes/guides/preferences/index.html

和/或使用 exe 文件附近的属性文件作为保存路径 https://docs.oracle.com/javase/7/docs/api/java/util/Properties.html

对于使用 Windows 打开,可以使用此架构,例如:

if (Desktop.isDesktopSupported()) {
Desktop desktop = Desktop.getDesktop();
if (desktop.isSupported(Desktop.Action.OPEN)) {
desktop.open(file);
}
}

https://docs.oracle.com/javase/7/docs/api/java/awt/Desktop.html

有关集合关联,请参阅: https://www.thewindowsclub.com/change-file-associations-windows可能有用 Have the ability to set Java application as default file opener?

关于java - 如何在启动时向我的 java 应用程序(如 .exe)传递文档的路径?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55980471/

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