[英]Java - Trying to display last modified date for the files in a folder
My problem is that when I try lastModified
function on files I get an error - method 'lastModified' not found
. 我的问题是,当我在文件上尝试lastModified
函数时,出现错误- method 'lastModified' not found
。 It only allows me to use the lastModified
function on folders, and I'm unsure how to fix this. 它只允许我在文件夹上使用lastModified
函数,但不确定如何解决此问题。 This is what I have so far: 这是我到目前为止的内容:
public static void main(String[] args) {
String path = "C:/Desktop/ExampleFolder";
String files;
File folder = new File(path);
File[] listOfFiles = folder.listFiles();
for (int i = 0; i < listOfFiles.length; i++) {
if (listOfFiles[i].isFile())
{
files = listOfFiles[i].getName();
SimpleDateFormat sdf = new SimpleDateFormat("MM-dd-yy HH:mm: a");
if (files.endsWith(".txt") || files.endsWith(".csv") || files.endsWith(".docx")) {
System.out.println("File Name: " + files + " , " + "Size: " + files.length() + " bytes " + " , " + "Last Modified : " + sdf.format(files.lastModified()) );
}
}
}
}
In your code you wrote files.lastModified()
where files
is a String
. 在您的代码中,您编写了files.lastModified()
,其中files
是一个String
。
Don't you mean following instead ? 您不是要跟随吗?
listOfFiles[i].lastModified()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.