java获取系统开机时间
来源:互联网 发布:java 按键 编辑:程序博客网 时间:2024/04/28 06:02
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; } }