royzhou1985 发表于 2013-2-5 02:43:07

Java执行DOS命令

public static void main(String[] args) throws InterruptedException {try {// String command = "C:\\Program Files\\Internet// Explorer\\Iexplore.exe www.google.cn";String command = "ping 192.168.1.1";Process process = Runtime.getRuntime().exec(command);String s = "";BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(process.getInputStream())); while ( (s=bufferedReader.readLine()) != null) System.out.println(s); process.waitFor();} catch (IOException ex) {}System.out.println(Test.class.getResource("")); System.out.println(Test.class.getResource("/")); // Class文件所在路径}
页: [1]
查看完整版本: Java执行DOS命令