日期:2014-05-17 浏览次数:20897 次
import java.io.BufferedInputStream; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; public class SystemTest { /** * @param args */ public static void main(String[] args) { //执行WINDOWS的CMD 命令 Runtime r = Runtime.getRuntime(); try { String[] sr = {"cmd","/c","dir d:\\."}; Process p = r.exec(sr); p.getInputStream(); BufferedReader br = null; BufferedInputStream bis = new BufferedInputStream(p.getInputStream()); br = new BufferedReader(new InputStreamReader(bis,"gb2312")); String ss = null; while((ss = br.readLine()) != null){ System.out.println(ss); } System.out.println(ss); } catch (IOException e) { e.printStackTrace(); } } }