ProcessBuilder实例启动一个新的应用程序

阅读更多
/**
	 * 启动应用程序
	 * 
	 * @param programName
	 * @return
	 * @throws IOException
	 */
	public static void startProgram(String programPath) throws IOException {
		log.info("启动应用程序:" + programPath);
		if (StringUtils.isNotBlank(programPath)) {
			try {
				String programName = programPath.substring(programPath.lastIndexOf("/") + 1, programPath.lastIndexOf("."));
				List list = new ArrayList();
				list.add("cmd.exe");
				list.add("/c");
				list.add("start");
				list.add("\"" + programName + "\"");
				list.add("\"" + programPath + "\"");
				ProcessBuilder pBuilder = new ProcessBuilder(list);
				pBuilder.start();
				// Desktop.getDesktop().open(new File(programPath));
			} catch (Exception e) {
				e.printStackTrace();
				log.error("应用程序:" + programPath + "不存在!");
			}
		}
	}

 

你可能感兴趣的:(乔乐共享,纵观千象,process,start,application)