zoukankan      html  css  js  c++  java
  • java调用计算机显示文档

     
    import java.awt.Desktop; 
    import java.io.File; 
    import java.io.IOException; 
     
    /**
     * Java调用系统默认程序打开本地文件
     * @see 这里提供了三种打开方式,大家可自行选取
     * @create Apr 23, 2013 1:00:37 AM
     * 
     */ 
    public class OpenLocalFile { 
        public static void main(String[] args) throws IOException { 
           // useAWTDesktop(); 
            useCMDCommand(); 
            //useLocalCommand(); 
        } 
         
         
        /**
         * 借助java.awt.Desktop打开
         * @see 打开的目录或文件名中允许包含空格
         */ 
        private static void useAWTDesktop() throws IOException{ 
            Desktop.getDesktop().open(new File("..\BaoDing_Shoop\保定商场商品管理系统项目帮助.doc")); 
        } 
         
         
        /**
         * 借助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", "G:\java\BaoDing_Shoop\保定商场商品管理系统项目帮助.doc"}); 
        } 
         
         
        /**
         * 借助本地安装程序打开
         * @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); 
        } 
    } 


  • 相关阅读:
    3.24
    3.23
    构建之法读书笔记2
    寒假学习day23
    寒假学习day22
    寒假学习day21
    寒假学习day20
    寒假学习day19
    寒假学习每周总结4
    寒假学习day18
  • 原文地址:https://www.cnblogs.com/jiangu66/p/3188509.html
Copyright © 2011-2022 走看看