java 语言运行exe或者直接打开文件(Windows下)

打开程序,如酷狗 String cmd =  "\"D://Program Files (x86)//KuGou//KGMusic//KuGou.exe\"";(注意字符的转义)

使用系统默认的软件直接打开文件 String cmd1 = "cmd.exe /c start C://Users//username//Desktop//test.pptx";

使用的方法:

	private void runCommand(String str){
		try {
			Runtime.getRuntime().exec(str);
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}



***************一下是网上找的*****************


打开文件

//打开工具的路径及名字

String toolsPath = "C:/WINDOWS/system32/notepad.exe ";

//被打开文件的路径及名字

String fileName = "test.txt";

try {

 

Runtime.getRuntime().exec(toolsPath+fileName);

} catch (IOException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

打开文件夹

try {

String[] cmd = new String[5];

String url = "C:/input";

cmd[0] = "cmd";

cmd[1] = "/c";

cmd[2] = "start";

cmd[3] = " ";

cmd[4] = url;

Runtime.getRuntime().exec(cmd);

} catch (IOException e) {

e.printStackTrace();

}

或者

Runtime.getRuntime().exec("cmd /c start C:/input");

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值