I want to be able to list the files in the current directory. I\'ve made something that should work but doesn\'t return all the file names.
File dir = new File(\
I used this answer with my local directory ( for example E://
) it is worked fine for the first directory and for the seconde directory the output made a java null pointer exception, after searching for the reason i discover that the problem was created by the hidden directory, and this directory was created by windows
to avoid this problem just use this
public void recursiveSearch(File file ) {
File[] filesList = file.listFiles();
for (File f : filesList) {
if (f.isDirectory() && !f.isHidden()) {
System.out.println("Directoy name is -------------->" + f.getName());
recursiveSearch(f);
}
if( f.isFile() ){
System.out.println("File name is -------------->" + f.getName());
}
}
}