[Solved]Method Search File Start B Returns Files Array Main Method Want Iterate Print Date Filenam Q37072740
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. the date in in
middle of the filename 20190416. However, for some reason it returnthe wrong date. this are the files -BProce.Arr.20190416.server10.gz, BProce.Arr.20190416..ball10.gz,BProce.Arr.20190416.ball23.gz..I want to printout04/16/2019,04/16/2019,04/16/2019. 3times since I have 3 files. butright now it printout 12/31/1969,12/31/1969,12/31/1969
public class test {
public static void main(String[] args) throws IOException,ParseException {
String [] x = find(“C:”);
for(String st: x) {
File file = new File(st);
Stringname=file.getName();
//extracting thenumbers
name=name.replaceAll(“[^0-9]”, “”);
DateFormatformatter = new SimpleDateFormat(“yyyymmdd”);
Date date =(Date)formatter.parse(name);
SimpleDateFormatnewFormat = new SimpleDateFormat(“mm/dd/yyyy”);
StringfinalString = newFormat.format(date);
System.out.println(finalString);
}
}
public static String[] findB(String rootPath){
File root = new File(rootPath);
// Filter files whose name start with “B”
FilenameFilter beginswithm = new FilenameFilter() {
public boolean accept(File directory, String filename) {
return filename.startsWith(“B”);
}
};
// array to store filtered file names
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

