使用ProcessBuilder类操作。import java.io.BufferedReader;import java.io.InputStream;import java.io.InputStreamReader;import java.util.LinkedList;public class TestProcessBuilder{public static void main ( String[] args ) throws Exception{ProcessBuilder builder = new ProcessBuilder ("cmd", "/c", "time 06:19:28.25");Process process = builder.start ();InputStream is = process.getInputStream ();InputStreamReader isr = new InputStreamReader (is, "GBK");BufferedReader br = new BufferedReader (isr);while (null != ( line = br.readLine () )){System.out.println (line);}br.close ();isr.close ();is.close ();process.destroy ();}}
取消
评论