I do not want to use traditional approach of creating a new file object for each of the path name(file/dir) i want to check the existence for. e.g in below code:
public class FileChecker {
public static void main(String args[]) {
File f1 = new File("home/usr/data1");
File f2 = new File("home/usr/data2")
if(f1.exists()){
System.out.println("File existed");
}else{
System.out.println("File not found!");
}
if(f2.exists()){
System.out.println("File existed");
}else{
System.out.println("File not found!");
}
}
}
I have to create a new object for each candidate file whose existence i want to check,I think this approach will monotonously fill heap space if my list of files(that need to be checked for existence is large). Is there any other approach to achieve the same without creating so many File objects?