【发布时间】:2017-04-19 05:42:18
【问题描述】:
我希望按照标题所说的去做。
部分解决方案:
例如在Windows 中,您可以使用下面的代码在默认资源管理器中打开一个文件并突出显示它。
(although it needs modification for files containing spaces):
/**
* Opens the file with the System default file explorer.
*
* @param path the path
*/
public static void openFileLocation(String path) {
if (InfoTool.osName.toLowerCase().contains("win")) {
try {
Runtime.getRuntime().exec("explorer.exe /select," + path);
} catch (IOException ex) {
Main.logger.log(Level.WARNING, ex.getMessage(), ex);
}
}
}
有用的链接:
相似但no way dublicates或未回答的链接:
How to use java code to open Windows file explorer and highlight the specified file?
Open a folder in explorer using Java
How can I open the default system browser from a java fx application?
更多解释:
-
有没有办法使用 JavaFX 做到这一点?
If not at least i need a link or some way to make the app system independence.I mean i don't know the default explorer for every OS that the application is going to work , i need a link or help doing that. -
我是否需要编写大量代码才能做到这一点?
-
有没有图书馆可以做到这一点?
-
Java9 支持吗?
最后:
很奇怪,对于如此常见的事情,我找不到答案和库。
在 Windows 10 中突出显示或选择的示例:
【问题讨论】:
-
我已准备好为那些找到答案的勇敢者提供赏金;)
-
Example of highlighted or selected in Windows 10:- 是的,Java 无法访问在 Windows 环境中运行的应用程序的单个 API。我确定为此您需要一种较低级别的语言。 -
@Sedrick Jefferson 随着 JavaFX 的不断发展,我认为它可能会通过 JNI 调用本机系统来提供这样的功能或库。实际上,如果出现这样的功能,那将是惊人的。包括第三方库在内的任何解决方案都被高度接受。可以看到 Swing 有桌面 API。
-
这个问题没有人回答真的很可惜。我也有同样的需求。
-
签名。差异机有差异文件浏览器,不知道如何适配更多操作系统。