您的位置:首页 > 编程语言 > Java开发

java获取系统开机时间

2011-11-22 17:34 239 查看
Runtime.getRuntime().exec来得到,

头疼,

上代码:

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class Test {

/**
* @param args
*/
public static void main(String[] args) throws Exception{
   System.out.println(Test.readSystemStartTime());
  
}
public static String readSystemStartTime() throws IOException, 
    InterruptedException { 
        Process process = Runtime.getRuntime().exec( 
            "cmd /c net statistics workstation"); 
        String startUpTime = ""; 
        BufferedReader bufferedReader = new BufferedReader( 
            new InputStreamReader(process.getInputStream())); 
        int i = 0; 
        String timeWith = ""; 
        while ((timeWith = bufferedReader.readLine()) != null) { 
           if (i == 3) { 
               System.out.println(timeWith); 
               startUpTime = timeWith; 
         } 
        i++; 
       } 
        process.waitFor(); 
        return startUpTime; 
} 
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: