I have a list of 50,000 paths, and I need to check if a file exists against each of these paths. Right now, I am checking each path independently as follows:
public static List<String> filesExist(String baseDirectory, Iterable<String> paths) throws FileNotFoundException{
File directory = new File(baseDirectory);
if(!directory.exists()){
throw new FileNotFoundException("No Directory found: " + baseDirectory );
}else{
if(!directory.isDirectory())
throw new FileNotFoundException(baseDirectory + " is not a directory!");
}
List<String> filesNotFound = new ArrayList<String>();
for (String path : paths) {
if(!new File(baseDirectory + path).isFile())
filesNotFound.add(path);
}
return filesNotFound;
}
Is there a way to improve it so as not to create 50,000 File objects? I also use guava. Is there any usefulness that can help me with the mass method exists()?
source
share