`

直接由Java获取文件的创建时间

阅读更多
import java.io.*;

public class getCreateFileTime {
  public static void main(String[] args) {
    try {
      Process p = Runtime.getRuntime().exec("cmd /C dir f:\\modify.log /tc");

      InputStream is = p.getInputStream();
      BufferedReader br = new BufferedReader(new InputStreamReader(is));
      String result;
      String getTime = null;
      while ((result = br.readLine()) != null) {
        String[] str = result.split(" ");
        for (int i = str.length - 1; i >= 0; i--) {
          if (str[i].equals("modify.log")) {
            getTime = str[0] + " " + str[2];
          }
        }
      }
      System.out.println("modifyInfoLoade.log 文件的创建日期是:" + getTime);
    } catch (java.io.IOException exc) {
      exc.printStackTrace();
    }
  }
}
 
分享到:
评论
1 楼 蓝月儿 2011-04-13  
学习了,感觉获取的不是啊

相关推荐

Global site tag (gtag.js) - Google Analytics