Java调用批处理或可执行文件
1 import java.io.BufferedReader; 2 import java.io.InputStreamReader; 3 4 public class Test { 5 public static void main(String[] args) { 6 String command = "cmd /c dir \\windows"; 7 String result; 8 try { 9 Process process = Runtime.getRuntime().exec(command); 10 BufferedReader bufferedReader = new BufferedReader( 11 new InputStreamReader(process.getInputStream())); 12 while ((result = bufferedReader.readLine()) != null){ 13 System.out.println(result);
14 } 15 process.waitFor(); 16 } catch (Exception e) { 17 e.printStackTrace(); 18 } 19 } 20 }