日期:2014-05-20  浏览次数:20971 次

java如何获取文件的创建时间,最后访问时间?[新手请指教]
file里只有个现成的获取文件最后修改时间。怎么去获取文件的创建时间,最后访问时间?

------解决方案--------------------
Java code

try {
            Process p = Runtime.getRuntime().exec(
                    "cmd /C dir F:\\test4\\a2.html /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("a2.html")) {
                        getTime = str[0] + " " + str[2];
                    }
                }
            }
            System.out.println("a2.html 文件的创建日期是:" + getTime);
        } catch (java.io.IOException exc) {
            exc.printStackTrace();
        }
        //
        String ss = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss")
                .format((new File("F:\\test4\\a2.html").lastModified()));
        System.out.println("最后修改时间:"+ss);