public static Exception checkFile ( final File file ) { Exception ex = null ; String error = null ; // check if the file does not exists... if ( ! file . exists ( ) ) { error = "The " + file + " does not exists." ; ex = new FileDoesNotExistException ( error ) ; return ex ; } // check if the file is not a directory... if ( ! file . isDirectory ( ) ) { error = "The " + file + " is not a directory." ; ex = new FileIsNotADirectoryException ( error ) ; return ex ; } final File [ ] ff = file . listFiles ( ) ; // If the file is null if ( ff == null ) { // it is security restricted error = "The " + file + " could not list the content." ; ex = new DirectoryHasNoContentException ( error ) ; } return ex ; }
Checks the File if it is a directory or if its exists or if it is empty .