怎么知道文件的生成时间?

csdn1111 2006-01-17 10:51:54
怎么知道文件的生成时间?
java.io.File()没有这个方法
...全文
105 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
阿钚 2006-01-17
  • 打赏
  • 举报
回复
import java.io.*;
public class Test {
public static void main(String[] args) {
try {
Process p = Runtime.getRuntime().exec("cmd /C dir c:\\temp\\xx.txt /tc");
InputStream is = p.getInputStream();
int i;
while((i=is.read())!=-1) System.out.print((char)i);
} catch (java.io.IOException exc) { exc.printStackTrace(); }
}
}

从里面提取吧

挑大梁 2006-01-17
  • 打赏
  • 举报
回复
import 少写了一个,java.sql.*
挑大梁 2006-01-17
  • 打赏
  • 举报
回复
import java.io.*;
import import java.text.SimpleDateFormat;
public class Test{
public static void main(String[] args){
try{
String strDateTime = "";
File f = new File("path/file");
long fLastMod = f.lastModified();
String datetimeformat = "yyyy-MM-dd HH:mm:ss";
SimpleDateFormat sdateformat = new SimpleDateFormat(datetimeformat);
Timestamp ts = new Timestamp(fLastMod);
strDateTime = sdateformat.format(ts);
}catch(Exception e){

}
}
}
masse 2006-01-17
  • 打赏
  • 举报
回复
创建时间不知道,
最后修改时间可以用

lastModified()

62,629

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧