title: NoSuchElementException in Scanner
body: <p>I am working on a kind-of parser (hobby project) which takes a Cpp file, reads through the comments in the file, and then tries to create a header file based on that.</p>
  
  <p>The problem I am facing is when the <code>java.util.Scanner</code> is about to read the very first line. The program stops and gives me the <code>NoSuchElementException</code>. I can't really figure out what should be wrong. I checked that both path and pathname are made correctly. The file must be there, and I can read fields on the Scanner object as well when I debug. So what's the problem exactly?</p>
  
  <p>Some was hinting at that it might think there are no lines in the file.</p>
  
  <p>Problem occurs at <code>while((line = scanner.next()) != null) {</code></p>
  
  <pre><code>@Override
  public void run() {
      Scanner scanner = null;
      String filename = "", path = "";
      StringBuilder puBuilder, prBuilder, viBuilder;
      puBuilder = new StringBuilder();
      prBuilder = new StringBuilder();
      viBuilder = new StringBuilder();
      for(File f : files) {
          try {
              filename = f.getName();
              path = f.getAbsolutePath();
              path = path.replace(filename, "");
              filename = filename.replace(".cpp", "");
              scanner = new Scanner(new FileReader(f));
          } catch (FileNotFoundException ex) {
              System.out.println("FileNotFoundException: " + ex.getMessage());
          }
  
          String line;
          String tag;
          while((line = scanner.next()) != null) {
              line = line.trim();
              if(line.startsWith(PUBLIC)) {
                  tag = PUBLIC;
  </code></pre>