[Solved]Method Search File Start B Returns Files Array Main Method Want Iterate Print Date Filenam Q37040780
I have a method that search a file that start by B and returnsfiles in Array. In main method I want iterate and print out theDate from filename. However, for some reason it return the wrongdate. this are the files – Bproces.log.20190413.snow.gz,Bproces.log.20190413.snow1.gz, Bproces.log.20190413.snow3.gz..Iwant to printout 04/13/2019,04/13/2019,04/13/2019. 3times since Ihave 3 files. but right now it printout12/31/1969,12/31/1969,12/31/1969
public class test {
public static void main(String[] args) throwsIOException, ParseException {
String [] x = find(“C:”);
for(String st: x) {
File file = newFile(st);
SimpleDateFormatsdf = new SimpleDateFormat(“MM/dd/yyyy”);
System.out.println(sdf.format(file.lastModified()));
}
}
public static String[] findB(String rootPath){
File root = newFile(rootPath);
// Filter files whose name startwith “B”
FilenameFilter beginswithm = newFilenameFilter() {
public booleanaccept(File directory, String filename) {
return filename.startsWith(“B”);
}
};
// array to store filtered filenames
String[] files =root.list(beginswithm);
String[] no = { “nofile” };
if (files == null) {
return no;
}
return files;
}
}
Expert Answer
Answer to I have a method that search a file that start by B and returns files in Array. In main method I want iterate and print o… . . .
OR

