title: Getting the list of packages in a java project
body: <p>I was trying to get the List of packages from a java src folder by parsing it(using Files). Irrespective of the package structure (some may be <strong>com.example.abc</strong>, some may be <strong>com.example.xxyz.pqr</strong>, some may be <strong>com.application</strong> etc.) i want to get the list of packages in the src folder. Here is the function i've written. I'm getting very strange outputs. Please help me.</p>
  
  <pre><code>public static void displayIt(File node) {
  
      File[] subNode = node.listFiles();
  
      if (subNode.length == 1) {
  
          for (File file : subNode) {
              if (file.isDirectory()) {
                  packageName = packageName + file.getName();
                  displayIt(file);
              }
          }
      }
  
      else {
          subFolders = new ArrayList&lt;String&gt;();
          for (File file : subNode) {
              // parent.add(file.getName());
              subFolders.add(file.getName());
              if (file.isDirectory()) {
                  File[] subDir = file.listFiles();
                  for (File tempFile : subDir) {
  
                      if (tempFile.isDirectory()) {
  
                          // temp=file.getName()+"."+tempFile.getName();
                          packageList
                                  .add(file.getName() + tempFile.getName());
  
                          displayIt(tempFile);
                      }
  
                  }
  
              }
  
              displayIt(file);
          }
      }
  
  }
  </code></pre>