我使用 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/