栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

使用Java确定Microsoft Office版本

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

使用Java确定Microsoft Office版本

一种方法是调用Windows ASSOC和FTYPE命令,捕获输出并进行解析以确定已安装的Office版本。

C:Usersme>assoc .xls.xls=Excel.Sheet.8C:Usersme>ftype Excel.sheet.8Excel.sheet.8="C:Program Files (x86)Microsoft OfficeOffice12EXCEL.EXE" /e

这是一个 简单的 例子:

import java.io.*;public class ShowOfficeInstalled {    public static void main(String argv[]) {      try {        Process p = Runtime.getRuntime().exec          (new String [] { "cmd.exe", "/c", "assoc", ".xls"});        BufferedReader input =          new BufferedReader (new InputStreamReader(p.getInputStream()));        String extensionType = input.readLine();        input.close();        // extract type        if (extensionType == null) {          System.out.println("no office installed ?");          System.exit(1);        }        String fileType[] = extensionType.split("=");        p = Runtime.getRuntime().exec          (new String [] { "cmd.exe", "/c", "ftype", fileType[1]});        input =          new BufferedReader (new InputStreamReader(p.getInputStream()));        String fileAssociation = input.readLine();        // extract path        String officePath = fileAssociation.split("=")[1];        System.out.println(officePath);      }      catch (Exception err) {        err.printStackTrace();      }    }  }

您可能想要添加更多错误检查,并且将练习从返回的路径中提取Office版本的解析作为练习;-)



转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/464092.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号