GOX*_*LUS 5 java io explorer javafx
我希望按照标题所说的去做。
部分解决方案:
例如,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);
}
}
}
Run Code Online (Sandbox Code Playgroud)
有用的链接:
相似但未no way dublicates
回答的链接:
如何使用java代码打开Windows文件资源管理器并突出显示指定文件?
更多解释:
有没有办法使用 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.
Run Code Online (Sandbox Code Playgroud)我需要编写大量代码才能做到这一点吗?
有没有图书馆可以这样做?
Java9 支持吗?
最后:
很奇怪,对于如此常见的事情,我找不到答案和图书馆。
非常感谢帮助:)
在 Windows 10 中突出显示或选择的示例:
小智 4
从 Java 9 开始,可以使用新方法 browserFileDirectory,因此您的方法将声明:
import java.awt.Desktop;
import java.io.File;
...
/**
* Opens the file with the System default file explorer.
*
* @param path the path
*/
public static void openFileLocation(String path) {
Desktop.getDesktop().browseFileDirectory(new File(path));
}
Run Code Online (Sandbox Code Playgroud)
有关更多信息,请参阅 javadoc: https://docs.oracle.com/javase/10/docs/api/java/awt/Desktop.html#browseFileDirectory(java.io.File)
归档时间: |
|
查看次数: |
4402 次 |
最近记录: |