I'm new to java programming. What I'm trying to achieve is to get file names with a specific pattern that I gather into a String array. I was able to print the results, instead of that, I want to get the file names into a string array so that I can further use the length of the array in the remainder of the program.
File folder = new File("/Test1/Test2/Test3/XYZ03/");
String target_file;
File[] listOfFiles = folder.listFiles();
for (int i = 0; i < listOfFiles.length; i++) {
if (listOfFiles[i].isFile()) {
target_file = listOfFiles[i].getName();
if (target_file.startsWith("XYZ03") && target_file.endsWith(".dat")) {
System.out.println("found" + " " + target_file);
}
}
}
List<String>(for example, useArrayList). You can populate it by doingfileNamesList.add(target_file).