title: Regarding selecting all the java files from project src folder
body: <p>I have developed a application in which user select the particular folder and it counts all the java files in that folder plus the line of code individually in those files and show at console but in a java project there are so many packages and right now I have to navigate until a particular package , I want to modify the application in such a way that when user select the particular project, he will then further navigate to only src folder and from src folder all the packages containing java files line of code will be counted. </p>
  
  <p>Please advise how to achieve that..below is my piece of code: </p>
  
  <pre><code>public class abc {
  
  
      /**
       * @param args
       * @throws FileNotFoundException
       */
      public static void main(String[] args) throws FileNotFoundException {
  
          JFileChooser chooser = new JFileChooser();
          chooser.setCurrentDirectory(new java.io.File("C:" + File.separator));
          chooser.setDialogTitle("FILES ALONG WITH LINE NUMBERS");
          chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
          chooser.setAcceptAllFileFilterUsed(false);
                  if (chooser.showOpenDialog(null) == JFileChooser.APPROVE_OPTION)
          {      Map&lt;String, Integer&gt; result = new HashMap&lt;String, Integer&gt;();
               File directory = new File(chooser.getSelectedFile().getAbsolutePath()); 
               int totalLineCount = 0;
               File[] files = directory.listFiles(new FilenameFilter(){
                    @Override
                    public boolean accept(File directory, String name) {
                        if(name.endsWith(".java"))
                        return true;
                      else
                        return false;              
                    }
                  }
     );
                for (File file : files)
              {
                  if (file.isFile())
                  {    Scanner scanner = new Scanner(new FileReader(file));
                      int lineCount = 0;
                       try
                      { for (lineCount = 0; scanner.nextLine() != null; lineCount++) ;
                            } catch (NoSuchElementException e)
                      {   result.put(file.getName(), lineCount);
                      totalLineCount += lineCount;  
                                      }
  
  
                  } }
                System.out.println("*****************************************");
                System.out.println("FILE NAME FOLLOWED BY LOC");
                System.out.println("*****************************************");
  
              for (Map.Entry&lt;String, Integer&gt; entry : result.entrySet())
              {   System.out.println(entry.getKey() + " ==&gt; " + entry.getValue());
              }
              System.out.println("*****************************************");
              System.out.println("SUM OF FILES SCANNED ==&gt;"+"\t"+result.size()); 
              System.out.println("SUM OF ALL THE LINES ==&gt;"+"\t"+ totalLineCount);
  
               }     
  
      }
  
  }
  </code></pre>
  
  <p>the problem with my code is now when I start my application an dialog box get opened in which I have to browse till the complete package folder which finally contains the java files but now I want to modify the application in such a way so that when file diaolog box get opened , user will navigate to project src folder only and from then onwards all the packages inside the src folder need to be scanned and all the files line of code,please advise..</p>
  
  <p>What I was thinking was...</p>
  
  <ul>
  <li>Given a File Object that represents a directory (we will call it Directory): </li>
  <li>Get all the Files in the Directory. </li>
  <li>For Each File in the Directory, (we will call it thisFile) do the following: </li>
  <li>If thisFile is a directory, start from the beginning use thisFile as the Directory </li>
  <li>Else, If thisFile is a .java file, count the lines of code </li>
  <li>Else, ignore thisFile </li>
  </ul>
  
  <p>This gets a whole lot easier if you separate the main into methods.</p>