这是我的代码:
File TempFiles = new File(Tempfilepath);
if (TempFiles.exists()) {
String[] child = TempFiles.list();
for (int i = 0; i < child.length; i++) {
Log.i("File: " + child[i] + " creation date ?");
// how to get file creation date..?
}
}
发布于 2010-09-16 16:53:48
下面是我会怎么做
// Used to examplify deletion of files more than 1 month old
// Note the L that tells the compiler to interpret the number as a Long
final int MAXFILEAGE = 2678400000L; // 1 month in milliseconds
// Get file handle to the directory. In this case the application files dir
File dir = new File(getFilesDir().toString());
// Obtain list of files in the directory.
// listFiles() returns a list of File objects to each file found.
File[] files = dir.listFiles();
// Loop through all files
for (File f : files ) {
// Get the last modified date. Milliseconds since 1970
Long lastmodified = f.lastModified();
// Do stuff here to deal with the file..
// For instance delete files older than 1 month
if(lastmodified+MAXFILEAGE<System.currentTimeMillis()) {
f.delete();
}
}
发布于 2010-03-06 03:55:20
文件创建日期不是Java File
类公开的可用数据。我建议你重新考虑你正在做的事情,改变你的计划,这样你就不需要它了。
发布于 2018-01-25 04:42:21
从API级别26开始,您可以执行以下操作:
File file = ...;
BasicFileAttributes attr = Files.readAttributes(file.toPath(), BasicFileAttributes.class);
long createdAt = attr.creationTime().toMillis();
https://stackoverflow.com/questions/2389225
复制相似问题