[英]How can pass my java application (as .exe) the path of a document on startup?
I use JSmooth to turn my java application (jar) into an executable. 我使用JSmooth将我的java应用程序(jar)变成可执行文件。 It´sa simple text editor, like notepad.
这是一个简单的文本编辑器,如记事本。 I want to use the "Open With" function of windows to open certain files with the exe.
我想使用windows的“打开方式”功能用exe打开某些文件。 For this, I only need the path of each file.
为此,我只需要每个文件的路径。 How do I do this?
我该怎么做呢?
I thought about using a java-property and calling it with System.getProperty("VariableName"), though I don´t know if this is possible. 我想过使用java-property并用System.getProperty(“VariableName”)调用它,虽然我不知道这是否可行。 ${EXECUTABLEPATH} just gets me the location of the MyApp.exe.
$ {EXECUTABLEPATH}只是让我获得MyApp.exe的位置。
For short properties may use Preferences.userNodeForPackage(MyExample.class); 对于简短属性,可以使用Preferences.userNodeForPackage(MyExample.class); and methods: get, put, flush.
和方法:get,put,flush。
https://docs.oracle.com/javase/8/docs/technotes/guides/preferences/index.html https://docs.oracle.com/javase/8/docs/technotes/guides/preferences/index.html
and/or to use properties file near your exe file for save paths https://docs.oracle.com/javase/7/docs/api/java/util/Properties.html 和/或使用exe文件附近的属性文件来保存路径https://docs.oracle.com/javase/7/docs/api/java/util/Properties.html
For open with Windows may use this schema for example: 对于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://docs.oracle.com/javase/7/docs/api/java/awt/Desktop.html
For set associations see: https://www.thewindowsclub.com/change-file-associations-windows may be usefull Have the ability to set Java application as default file opener? 对于集合关联,请参阅: https : //www.thewindowsclub.com/change-file-associations-windows可能有用l能否将Java应用程序设置为默认文件打开器?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.