启动时如何将我的Java应用程序(如.exe)传递给文档的路径?

时间:2019-05-04 07:31:15

标签: java windows exe file-association

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

我考虑过使用Java属性并用System.getProperty(“ VariableName”)进行调用,尽管我不知道这是否可行。 $ {EXECUTABLEPATH}只是让我获取MyApp.exe的位置。

1 个答案:

答案 0 :(得分:0)

对于简短属性,可以使用Preferences.userNodeForPackage(MyExample.class); 和方法:获取,放置,冲洗。
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?