I have the following program:
public class filtrado {
public static void main(String[] args) throws IOException {
try{
File f = new File("."); // current directory
FilenameFilter textFilter = new FilenameFilter() {
public boolean accept(File dir, String name) {
String lowercaseName = name.toLowerCase();
return lowercaseName.startsWith("g");
}
};
File[] files = f.listFiles(textFilter);
for (File file : files) {
if (file.isDirectory()) {
System.out.print("directory:");
} else {
System.out.print(" file:");
}
System.out.println(file.getCanonicalPath());
}
}catch (Exception e) {
}
}
}
Basically the operation is as follows: I look in my directory for any file that starts with "g". And classifies it into a directory or file.
But I need something else that I do not know how to do. I need when I can not find any file that lets me know, for example: There is no File / Directory that starts with G.
How do I do it?