热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

java中打开文件显示_在默认文件资源管理器中打开文件,并使用JavaFX或普通Java突出显示它...

我想做标题所说的.部分解决方案例如,在Windows中,您可以使用以下代码在默认资源管理器中打开文件并突出显示它.(虽然它需要修改包含空格的文件):***Openst

我想做标题所说的.

部分解决方案

例如,在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);

}

}

}

有用的链接:

类似的链接,但没有道德或没有回答的链接:

更多解释:

>有没有办法使用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中突出显示或选中的示例:

P8d4D.png

最佳答案 好的,我知道可能会迟到但我已经找到了答案.

从Java 9开始,可以使用新方法browseFileDirectory,因此您的方法将声明:

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));

}

我希望它对你有所帮助.



推荐阅读
author-avatar
海天豆浆
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有