`
royzhou1985
  • 浏览: 249984 次
  • 性别: Icon_minigender_1
  • 来自: 广州
社区版块
存档分类
最新评论

Java执行DOS命令

    博客分类:
  • Java
阅读更多
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文件所在路径
	}

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics