I have a directory, and inside it are files are named \"a_id_XXX.zip\"
.
How do check if a file exists given an id
and File dir
i created zip files named with a_id_123.zip ,a_id_124.zip ,a_id_125.zip ,a_id_126.zip and it looks like working fine but i'm not sure if it's proper answer for you. Output will be the following if files listed above exists
found a_id_126.zip
public static void main(String[] args) {
String pathToScan = ".";
String fileThatYouWantToFilter;
File folderToScan = new File(pathToScan); // import -> import java.io.File;
File[] listOfFiles = folderToScan.listFiles();
for (int i = 0; i < listOfFiles.length; i++) {
if (listOfFiles[i].isFile()) {
fileThatYouWantToFilter = listOfFiles[i].getName();
if (fileThatYouWantToFilter.startsWith("a_id_")
&& fileThatYouWantToFilter.endsWith(".zip")) {
System.out.println("found" + " " + fileThatYouWantToFilter);
}
}
}
}