23,404
社区成员
发帖
与我相关
我的任务
分享
public static void main(String[] args) throws Exception {
File file = new File("e:/teset.txt");
if (file.exists()) {
Calendar cal = Calendar.getInstance();
cal.setTimeInMillis(file.lastModified());
String time =
cal.get(Calendar.YEAR) + "/" + (cal.get(Calendar.MONTH) + 1) + "/" + cal.get(Calendar.DAY_OF_MONTH) +
" " +
cal.get(Calendar.HOUR_OF_DAY) + ":" + cal.get(Calendar.MINUTE) + ":" + cal.get(Calendar.SECOND);
System.out.println("文件名:"+ file.getName() + ", 文件路径:" + file.getPath() + ", 文件大小:" + file.length()/1024 +
"kb" + "最后修改时间:" + time);
} else {
FileOutputStream outputStream = new FileOutputStream(file);
outputStream.write(0);
outputStream.close();
}
}