我想按照标题所说的去做。
部分解决方案:
例如,在 Windows
中,您可以使用下面的代码在默认资源管理器中打开一个文件并突出显示它。
(虽然它需要修改包含空格的文件
):
/**
* 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);
}
}
}
有用的链接:
相似但无法重复
或未回答的链接:
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 中突出显示或选择的示例:
最佳答案
window
Runtime.getRuntime().exec("explorer /select, <file path>")
Linux
Runtime.getRuntime().exec("xdg-open <file path>");
MacOS
Runtime.getRuntime().exec("open -R <file path>");
关于java - 在默认文件资源管理器中打开文件并使用 JavaFX 或纯 Java 突出显示它,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40963947/