title: how to extract data from text file in Java
body: <p><pre>
  while (myFile.hasNextLine()) {</p>
  
  <code>        if(myFile.next().equals("Oval")) {
              System.out.println("this is an Oval");
  
          }
  
          else if(myFile.next().equals("Rectangle")) {
              System.out.println("this is an Rectangle");
  
          } 
  </code></pre>
  
  <p>the file contains the following<br/>
  Oval    10 10 80 90 Red<br/>
  Oval    20 20 50 60 Blue<br/>
  Rectangle 10 10 100 100 Green<br/></p>
  
  <p>I want to extract the data and pass them to a specific constructor according to the type indicated at the beginning of the line.</p>
  
  <p>but I am getting this weird output </p>
  
  <blockquote>
    <p>this is an Oval
    Exception in thread "main" java.util.NoSuchElementException
    this is an Rectangle
        at java.util.Scanner.throwFor(Scanner.java:907)
    this is an Rectangle
        at java.util.Scanner.next(Scanner.java:1416)
        at TestMain.main(TestMain.java:33)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:601)
        at com.intellij.rt.execution.application.AppMain.main(AppMain.java:134)</p>
  </blockquote>
  
  <p>Process finished with exit code 1</p>