JAVA中调用CMD命令,并输出执行结果

package com.wzw.util;

import java.io.BufferedReader;
import java.io.InputStreamReader;

public class CmdDemo {

		public static void main(String[] args) {
			BufferedReader br = null;
			try {
				Process p = Runtime.getRuntime().exec("net user");
				br = new BufferedReader(new InputStreamReader(p.getInputStream()));
				String line = null;
				while ((line = br.readLine()) != null) {
					System.out.println(line);
				}
			} catch (Exception e) {
				e.printStackTrace();
			} finally {

				if (br != null) {
					try {
						br.close();
					} catch (Exception e) {
						e.printStackTrace();
					}
				}
			}
		}
	}



执行结果:


\\PC-20140327DFCW 的用户帐户

-------------------------------------------------------------------------------
Administrator            Guest                    
命令成功完成。




JAVA中调用CMD命令,并输出执行结果,布布扣,bubuko.com

JAVA中调用CMD命令,并输出执行结果

上一篇:spring security运行流程图


下一篇:基于Tkinter利用python实现颜色空间转换程序