title: if Folder Contain File Then it Shows Else ignore in Java?
body: <p>If Folder Contain File then only Display that Directory name in Java. how can we do that . as of now i am Getting Main Folder and Sub Folder name. please Find snapshot for better understanding</p>
  
  <pre><code>public class GetChild {
  
  
      private static FileFilter onlyDirectories = new FileFilter() {
          @Override
          public boolean accept(File file) {
              return file.isDirectory();
          }
      };
       public static void main(String[] args) {
          File currentDir = new File("E:\\Folder"); // current directory
          displayDirectoryContents(currentDir);
      }
  
      public static void displayDirectoryContents(File dir) {
          StringBuilder sb1 = new StringBuilder("");
         doDisplayDirectoryContents(dir, sb1);
  
      }
  
      private static void doDisplayDirectoryContents(File dir, StringBuilder sb1) {
          File[] files = dir.listFiles(onlyDirectories);
          for (File file : files) {
              try {
                  System.out.println("file.getCanonicalPath()===&gt;" + file.getCanonicalPath());
                  doDisplayDirectoryContents(file, sb1);
              } catch (IOException e) {
                  e.printStackTrace();
              }
          }
        }
  }
  </code></pre>
  
  <p><img src="https://i.stack.imgur.com/Lv4XH.jpg" alt="enter image description here"></p>