zoukankan      html  css  js  c++  java
  • 用java打开一个本地文件

    以下有三种方式打开

    /**

        * 借助java.awt.Desktop打开

        * @see 打开的目录或文件名中允许包含空格

        */

        private static void useAWTDesktop() throws IOException{

        Desktop.getDesktop().open(new File("D:/my local/测试用例.xls"));

        }

        /**

        * 借助cmd命令打开

        * @see WPS文字--------Runtime.getRuntime().exec("cmd /c start wps")

        * @see WPS表格--------Runtime.getRuntime().exec("cmd /c start et")

        * @see WPS演示--------Runtime.getRuntime().exec("cmd /c start wpp")

        * @see Office Word---Runtime.getRuntime().exec("cmd /c start winword")

        * @see Office Excel--Runtime.getRuntime().exec("cmd /c start excel")

        */

        private static void useCMDCommand() throws IOException{

        //若打开的目录或文件名中不包含空格,就用下面的方式

        //Runtime.getRuntime().exec("cmd /c start D:/mylocal/测试用例.xls");

        //(可以'运行'或'Win+R',然后输入'cmd /?'查看帮助信息)

        Runtime.getRuntime().exec(new String[]{"cmd.exe", "/c", "D:/my local/测试用例.xls"});

        }

        /**

        * 借助本地安装程序打开

        * @see 若打开的目录或文件名中包含空格,它就无能为力了..不过本地程序的安装目录允许含空格

        */

        private static void useLocalCommand() throws IOException{

        String etCommand = "D:/Program Files/WPS/8.1.0.3526/office6/et.exe";

        String filePath = "D:/mylocal/测试用例.xls";

        Runtime.getRuntime().exec(etCommand + " " + filePath);

        }

        }

  • 相关阅读:
    Redhat 7使用CentOS 7的Yum网络源
    指定YUM安装包的体系结构或版本
    CURL常用命令
    VIM技巧之去除代码行号并缩进代码
    VIM 中鼠标选择不选中行号
    linux服务器性能优化
    阻塞,非阻塞,同步,异步
    WEB三层架构与MVC
    mvc与三层结构
    Centos环境下Tomcat启动缓慢
  • 原文地址:https://www.cnblogs.com/edver/p/4645916.html
Copyright © 2011-2022 走看看