当前位置: 首页 > 工具软件 > Todo.EXE > 使用案例 >

java打开exe程序

赫连彬炳
2023-12-01

 

package com.test;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Executecmd {

	public static void main(String[] args) {
        //exe文件路径
		cuteCmd("D:\\debug\\WebBrowserShangHai.exe");
	}
	
	public static String cuteCmd(String command){
		Runtime runtime = Runtime.getRuntime();
		StringBuilder builder = null;
		try {
			Process process = runtime.exec("cmd /c start " + command);
			BufferedReader brBufferedReader = new BufferedReader(new InputStreamReader(process.getInputStream(), "UTF-8"));
			String line = "";
			builder = new StringBuilder();
			while ((line = brBufferedReader.readLine()) != null) {
				System.out.println(line);
				builder.append(line);
			}
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		return builder.toString();
	}
}

 

 

 

 

 

 

 

 

 

参考:https://blog.csdn.net/songyanfei1205/article/details/81483321

 类似资料: