Reputation: 23
My problem is that when I try lastModified
function on files I get an error - method 'lastModified' not found
. It only allows me to use the lastModified
function on folders, and I'm unsure how to fix this. 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()) );
}
}
}
}
Upvotes: 0
Views: 634
Reputation: 15070
In your code you wrote files.lastModified()
where files
is a String
.
Don't you mean following instead ?
listOfFiles[i].lastModified()
Upvotes: 1