Java 打开文件的两种方式

import java.awt.Desktop;
import java.io.File;
import java.io.IOException;

public class LnkDemo {

    public static void main(String[] args) throws IOException {
        File f=new File("d://com.lnk");
        System.out.println(f.exists());
        System.out.println(f.isDirectory());
        Runtime.getRuntime().exec("explorer /e,/select,"+f.getAbsolutePath());
//        Desktop.getDesktop().open(f);
    }

}

摘要

本文讲述explorer.exe(资源管理器)的命令行。

语法

EXPLORER.EXE [/n][/e][,/root,<object>][[,/select],<sub object>]

/n: 默认选项,用我的电脑视图为每个选中的item打开一个单独的窗口,  即使该窗口已经被打开。

/e: 使用资源管理器视图。资源管理器视图和Windows 3.x的文件管理器非常相似。

/root,<object>: 指定视图目录根,默认使用桌面作为根目录。

/select,<sub object>: 选中指定对象。如果使用"/select" , 则父目录被打开,并选中指定对象

例子

打开资源管理器视图并以C:Windows为目录根浏览

explorer /e,/root,C:Windows

打开资源管理器视图并选中Calc.exe

explorer /e,/select,c:windowssystem32calc.exe

注意:/root和/select最好不要同时使用。

http://www.cnblogs.com/ymind/archive/2012/03/30/explorer-command-args.html

原文地址:https://www.cnblogs.com/softidea/p/4573401.html