java - 打开文件以查看其内容

标签 java file-io

<分区>

我有一个文件列表。让我们说它看起来:

String[] lst = new String[] {
    "C:\\Folder\\file.txt", 
    "C:\\Another folder\\another file.pdf"
};

我需要一些方法来使用默认程序打开这些文件,让我们用记事本说“file.txt”,用 Adob​​eReader 说“另一个文件.pdf”等等。

有人知道吗?

最佳答案

有一个方法可以做到这一点:

java.awt.Desktop.getDesktop().open(file);

Java文档:

Launches the associated application to open the file.

If the specified file is a directory, the file manager of the current platform is launched to open it.

关于java - 打开文件以查看其内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16002926/

相关文章:

java - 无法使用 HttpServletResponse 下载文件

java - 用于 C/C++ 和 Java 的 Eclipse IDE

java - 使用 java.util.scanner 读取和解析文件

java - 创建 JPanel 背景

java - JNI 中未声明的异常

python - 第一次写脚本,不知道用什么语言(解析excel等文件)

java - 无法从 SD 卡读取保存的对象

c - 如果文件有空格则读取数据

java - 将 Assets 文件夹子目录复制到外部存储中的特定文件夹

php - 在写入时将文件推送到网络浏览器