title: Regarding line of code
body: <p>Modified the code this time the objective to count the line of code was perfect below is the piece of code..</p>
  
  <pre><code> /**
       * @param args
       * @throws FileNotFoundException
       */
      private static int totalLineCount = 0;
      private static int totalFileScannedCount = 0;
  
      public static void main(final String[] args) throws Exception {
  
          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;File, Integer&gt; result = new HashMap&lt;File, Integer&gt;();
              File directory = new File(chooser.getSelectedFile().getAbsolutePath());
  
              List&lt;File&gt; files = getFileListing(directory);
  
              // print out all file names, in the the order of File.compareTo()
              for (File file : files) {
                 // System.out.println("Directory: " + file);
                  getFileLineCount(result, file);
                  //totalFileScannedCount += result.size(); //saral
              }
  
              System.out.println("*****************************************");
              System.out.println("FILE NAME FOLLOWED BY LOC");
              System.out.println("*****************************************");
  
              for (Map.Entry&lt;File, Integer&gt; entry : result.entrySet()) {
                  System.out.println(entry.getKey().getAbsolutePath() + " ==&gt; " + entry.getValue());
              }
              System.out.println("*****************************************");
              System.out.println("SUM OF FILES SCANNED ==&gt;" + "\t" + totalFileScannedCount);
              System.out.println("SUM OF ALL THE LINES ==&gt;" + "\t" + totalLineCount);
          }
  
      }
  
  
      public static void getFileLineCount(final Map&lt;File, Integer&gt; result, final File directory)
              throws FileNotFoundException {
          File[] files = directory.listFiles(new FilenameFilter() {
  
              public boolean accept(final File directory, final 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;
                  totalFileScannedCount ++; //saral
                  try {
  
                      /*for (lineCount = 0; scanner.nextLine() != null;lineCount++ ) { //saral
                          ;
  
  
                      }*/
  
  
                      while (scanner.hasNextLine()) {
                             String line = scanner.nextLine().trim();
                             if (!line.isEmpty()) {
                                System.out.println("debug--&gt;"+line); // to debug cross checked that no whitespaces are there 
                               lineCount++;
                             }
                      }
  
                       result.put(file, lineCount);
                       totalLineCount += lineCount;                               
                  } catch (NoSuchElementException e) {
                       e.printStackTrace();
                  }
              }
          }
  
      }
  
      /**
       * Recursively walk a directory tree and return a List of all Files found;
       * the List is sorted using File.compareTo().
       * 
       * @param aStartingDir
       *            is a valid directory, which can be read.
       */
      static public List&lt;File&gt; getFileListing(final File aStartingDir) throws FileNotFoundException {
          validateDirectory(aStartingDir);
          List&lt;File&gt; result = getFileListingNoSort(aStartingDir);
          Collections.sort(result);
          return result;
      }
  
      // PRIVATE //
      static private List&lt;File&gt; getFileListingNoSort(final File aStartingDir) throws FileNotFoundException {
          List&lt;File&gt; result = new ArrayList&lt;File&gt;();
          File[] filesAndDirs = aStartingDir.listFiles();
          List&lt;File&gt; filesDirs = Arrays.asList(filesAndDirs);
          for (File file : filesDirs) {
              if (file.isDirectory()) {
                  result.add(file);
              }
              if (!file.isFile()) {
                  // must be a directory
                  // recursive call!
                  List&lt;File&gt; deeperList = getFileListingNoSort(file);
                  result.addAll(deeperList);
              }
          }
          return result;
      }
  
      /**
       * Directory is valid if it exists, does not represent a file, and can be
       * read.
       */
      static private void validateDirectory(final File aDirectory) throws FileNotFoundException {
          if (aDirectory == null) {
              throw new IllegalArgumentException("Directory should not be null.");
          }
          if (!aDirectory.exists()) {
              throw new FileNotFoundException("Directory does not exist: " + aDirectory);
          }
          if (!aDirectory.isDirectory()) {
              throw new IllegalArgumentException("Is not a directory: " + aDirectory);
          }
          if (!aDirectory.canRead()) {
              throw new IllegalArgumentException("Directory cannot be read: " + aDirectory);
          }
      }
  </code></pre>
  
  <p>but the issue is that when it is displaying the result on console it throws the below exception please advise how to overcome from that</p>
  
  <pre><code>*****************************************
  FILE NAME FOLLOWED BY LOC
  *****************************************
  C:\Users\vaio\Desktop\Demo\fg\src\asd\abv.java ==&gt; 9
  *****************************************
  SUM OF FILES SCANNED ==&gt;    1
  SUM OF ALL THE LINES ==&gt;    9
  Exception while removing reference: java.lang.InterruptedException
  java.lang.InterruptedException
      at java.lang.Object.wait(Native Method)
      at java.lang.ref.ReferenceQueue.remove(Unknown Source)
      at java.lang.ref.ReferenceQueue.remove(Unknown Source)
      at sun.java2d.Disposer.run(Unknown Source)
      at java.lang.Thread.run(Unknown Source)
  </code></pre>