java执行cmd命令
import java.io.BufferedReader;import java.io.IOException;import java.io.InputStream;import java.io.InputStreamReader;public class Tests {public static void main(String args[]) { String javaExcute="regedit";//javaExcute为你要在CMD中执行的字符串 Process p; try { //执行CMD代码,返回一个Process p = Runtime.getRuntime().exec(javaExcute); InputStream is = p.getInputStream(); //得到相应的控制台输出信息 InputStreamReader bi = new InputStreamReader(is); BufferedReader br = new BufferedReader(bi); String message; message = br.readLine(); while(message != null && !"".equals(message)){ //将信息输出 System.out.println(message); message = br.readLine(); } } catch (IOException e) { e.printStackTrace(); return; } }}
?