擷取cmd命令,精確到分
- package lihan;
- import java.io.BufferedReader;
- import java.io.File;
- import java.io.FileReader;
- import java.io.IOException;
- import java.io.InputStreamReader;
- import java.util.ArrayList;
- import java.util.List;
- /**
- * 取tomcat次已耗用時間
- * @author 李晗
- *
- */
- public class readRunTime {
- /**
- * 主函數 (use testing)
- * @param args
- * @throws IOException
- */
- public static void main(String[] args) throws IOException {
- try {
- String str=readSystemStartTime();
- System.out.print(str);
- } catch (InterruptedException e) {
- // TODO 自動產生 catch 塊
- e.printStackTrace();
- }
-
- }
-
- 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.substring(x,y);
- startUpTime = timeWith;
- }
- i++;
- }
- process.waitFor();
- return startUpTime;
- }
- }
輸出結果:
統計資料開始於 2008/11/27 下午 08:03
統計資料開始於 2008/11/27 下午 08:03