直接由Java獲取文件的創建時間

 
  1. import java.io.*;   
  2.   
  3. public class getCreateFileTime {   
  4.   public static void main(String[] args) {   
  5.     try {   
  6.       Process p = Runtime.getRuntime().exec("cmd /C dir f:\\modify.log /tc");   
  7.   
  8.       InputStream is = p.getInputStream();   
  9.       BufferedReader br = new BufferedReader(new InputStreamReader(is));   
  10.       String result;   
  11.       String getTime = null;   
  12.       while ((result = br.readLine()) != null) {   
  13.         String[] str = result.split(" ");   
  14.         for (int i = str.length - 1; i >= 0; i--) {   
  15.           if (str[i].equals("modify.log")) {   
  16.             getTime = str[0] + " " + str[2];   
  17.           }   
  18.         }   
  19.       }   
  20.       System.out.println("modifyInfoLoade.log 文件的創建日期是:" + getTime);   
  21.     } catch (java.io.IOException exc) {   
  22.       exc.printStackTrace();   
  23.     }   
  24.   }   
  25. }  
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章