以下有三种方式打开
1.借助java.awt.Desktop打开
/**
* @see 打开的目录或文件名中允许包含空格
*/
private static void useAWTDesktop() throws IOException{
Desktop.getDesktop().open(new File(\"D:/my local/测试用例.xls\"));
}
2.借助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\"});
}
3. 借助本地安装程序打开
/**
* @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);
}
继续阅读与本文标签相同的文章
ICP经营许可证该怎么办理
自由区白皮书
-
缙云“人才·科技”峰会人才项目路演成功举行
2026-05-19栏目: 教程
-
谷歌发布Nest mini音箱:音质增强 售价49美元
2026-05-19栏目: 教程
-
微信转账还能换颜色?好友都懵了!
2026-05-19栏目: 教程
-
为何许多学生都用QQ,而步入社会后就变成了微信?理由让人泪目
2026-05-19栏目: 教程
-
微信小程序“模板消息”优化 支持一次性和长期性订阅消息
2026-05-19栏目: 教程
