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

我想做标题所说的.

部分解决方案

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

}

我希望它对你有所帮助.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
您好!对于您的需求,我可以帮助您编写一个使用JavaFX的程序来实现手动选择文件文件打开高光谱.dat数据并显示在下方图片的功能。下面是一个简单的示例代码: ```java import javafx.application.Application; import javafx.stage.FileChooser; import javafx.stage.Stage; import javafx.scene.Scene; import javafx.scene.control.Button; import javafx.scene.image.Image; import javafx.scene.image.ImageView; import javafx.scene.layout.VBox; import java.io.File; public class SpectralDataViewer extends Application { private ImageView imageView; public static void main(String[] args) { launch(args); } @Override public void start(Stage primaryStage) { Button openButton = new Button("选择文件夹"); openButton.setOnAction(e -> openSpectralData(primaryStage)); imageView = new ImageView(); imageView.setPreserveRatio(true); VBox vbox = new VBox(openButton, imageView); Scene scene = new Scene(vbox, 400, 400); primaryStage.setTitle("高光谱数据查看器"); primaryStage.setScene(scene); primaryStage.show(); } private void openSpectralData(Stage primaryStage) { FileChooser fileChooser = new FileChooser(); fileChooser.getExtensionFilters().add(new FileChooser.ExtensionFilter("DAT文件", "*.dat")); File folder = fileChooser.showOpenDialog(primaryStage).getParentFile(); if (folder != null) { File[] files = folder.listFiles((dir, name) -> name.toLowerCase().endsWith(".dat")); if (files != null && files.length > 0) { File dataFile = files[0]; // TODO: 解析并处理高光谱数据 displaySpectralData(dataFile); } } } private void displaySpectralData(File dataFile) { Image image = new Image(dataFile.toURI().toString()); imageView.setImage(image); } } ``` 您可以使用上述代码作为起点,根据需要进一步完善和调整。在打开文件夹选择对话框,程序会筛选出扩展名为".dat"的文件,您可以根据实际情况进行修改。在`displaySpectralData`方法,您可以添加逻辑来解析和处理高光谱数据,并将其显示在下方的图片视图。 希望这可以帮助到您!如有任何问题,请随时提问。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值