I'm trying to write a Java code which finds all files containing a determined a substring in the filename. That substring is a dynamic input of the program so it's stored in a string variable, named here "log3":
File fl = new File(dir); //fl is the directory in which look for files
File[] matchingFiles = fl.listFiles(new FileFilter() {
public boolean accept(File x) {
return (x.getName().contains(log3));
}
});
The problem is that when I compile the code I get this error:
local variable log3 is accessed from within inner class; needs to be
declared final
return (x.getName().contains(log3);
^