Search Java Code Snippets

  Help us in improving the repository. Add new snippets through 'Submit Code Snippet ' link.

#Java - Code Snippets for '#File.isDirectory' - 3 code snippet(s) found

 Sample 1. Method to get all files from a directory recursively

List<File> fileList = new ArrayList();

List<File> read(String dir) throws IOException{
File directory = new File(dir);
File[] fList = directory.listFiles();
for(File file:fList){
} else {
return fileList;

   Like      Feedback     file handling   file   isDirectory()  .getPath()   recursion

 Sample 2. Method to check if the the file exists and not a directory

public static boolean isOleFile(File file)
   if ((file == null) || (!file.exists()) || (file.isDirectory())) {
      return false;

   return true;

   Like      Feedback     file handling  check if file exists  File class  check if file is a directory  file.isDirectory  file.exists

 Sample 3. Get only sub directories in a directory using FileFilter

File dir = new File("C:/Folder");

File[] subdir = dir.listFiles(new FileFilter() {
   public boolean accept(File file) {
      return file.isDirectory();

   Like      Feedback     FileFilter

Subscribe to Java News and Posts. Get latest updates and posts on Java from
Enter your email address:
Delivered by FeedBurner