Java启动本机exe程序
转载自:www.ablanxue/shtml/201411/25906_1.shtml
Java启动(执行)本机应用程序EXE的三种方式
Java代码
// 第一种方式:利用cmd方式
/**
* 执行cmd命令
*
* @param command
* @throws IOException
*/
public static String executeCmd(String command) throws IOException {
log.info("Execute command : " + command);
Runtime runtime = Runtime();
Process process = ("cmd /c " + command);
BufferedReader br = new BufferedReader(new InputStream(), "UTF-8"));
String line = null;
StringBuilder build = new StringBuilder();
while ((line = br.readLine()) != null) {
log.info(line);
build.append(line);
}
String();
}
executeCmd(start "AXAdWebBrowser" "D:\");
Java代码
// 第二种方式:利用<span >ProcessBuilder调用cmd方式</span>
/**
* 启动应用程序
*
* @param programName
* @return
* @throws IOException
*/
public static void startProgram(String programPath) throws IOException {
log.info("启动应用程序:" + programPath);
if (StringUtils.isNotBlank(programPath)) {
java源代码加密 try {
String programName = programPath.substring(programPath.lastIndexOf("/") + 1, programPath.lastIndexOf("."));
List<String> list = new ArrayList<String>();
list.add("");
list.add("/c");
list.add("start");
list.add("\"" + programName + "\"");
list.add("\"" + programPath + "\"");
ProcessBuilder pBuilder = new ProcessBuilder(list);
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论