title: Parsing input from a file using Scanner. JAVA
body: <p>I am brand new to java and I am creating a file directory that stores movies and information about the movies. The movies and info are stored in a file like this: </p>
  
  <pre><code>Movie Title 
  Rating Year Reviews Month Day Year
  </code></pre>
  
  <p>Title on first line and other info on the second line. So with multiple movies it looks like this:</p>
  
  <pre><code>Movie Title
  Rating Year Reviews Month Day Year
  Movie Title
  Rating Year Reviews Month Day Year
  Movie Title
  Rating Year Reviews Month Day Year
  </code></pre>
  
  <p>...and so on. I have a method that prints the movies to the console but I am running into a problem formatting the movies correctly. The movie info should be formatted like this:</p>
  
  <pre><code>   Star Wars     PG    1977   5 stars  1/5/2018
  </code></pre>
  
  <p>Each column should be aligned properly. The title, rating, and year should be left aligned; the number of
  stars and date right aligned.</p>
  
  <p>The First time it prints the movie info out exactly how I want, but when I add multiple movies it messes things up. Here is my code, I believe the problem is in the listMovies method where I try to format the output, but I included all my code in case something is messed up somewhere else.</p>
  
  <pre><code>public class Directory 
  {
     private static final String dir = "data/cs2410-directory.data";
     String mTitle,mRat,mRel,mRev,mM,mD,mY;
  
  public Directory()
  {
      mTitle = "Movie Title";
      mRat = "Rating";
      mRel = "Year";
      mRev = "Reviews";
      mM = "Month";
      mD = "Day";
      mY ="Year";
      insertMovie();
      listMovies();
  }
  
  
  private void insertMovie()
  {
      PrintWriter dirIn = null;
  
      try
      {
          dirIn = new PrintWriter(new FileOutputStream(dir,true));
      }
      catch (FileNotFoundException e)
      {
          e.printStackTrace();
      }
      dirIn.println(mTitle);
      dirIn.println(mRat+" "+mRel+" "+mRev+" "+mM+" "+mD+" "+mY);
      dirIn.close();
      System.out.print("The following movie has been added to the directory:\n");
      System.out.print(mTitle+" ("+mRel+") "+mRat+"\n");
      System.out.print("Stars: "+mRev+"\n");
      System.out.print("Last Watched: "+mM+"/"+mD+"/"+mY+"\n");
  }
  
  private void listMovies()
  {
      Scanner dirOut = null;
  
      try
      {
          dirOut = new Scanner(new FileReader(dir));
      }
      catch (FileNotFoundException e)
      {
          e.printStackTrace();
      }
      while (dirOut.hasNext()) //PROBLEM
      {
          System.out.printf("%-15s%-10s%-10s%5s%10s/%s/%s\n", dirOut.nextLine(),dirOut.next()
                  ,dirOut.next(),dirOut.next(),dirOut.next(),dirOut.next(),dirOut.next());
      }
      dirOut.close();
  }
  
  public static void main(String[] args)
  {
      new Directory();
  }
  </code></pre>
  
  <p>This is the output after one movie (running program once) which is how it is supposed to look:</p>
  
  <pre><code>The following movie has been added to the directory:
  Movie Title (Year) Rating
  Stars: Reviews
  Last Watched: Month/Day/Year
  Movie Title    Rating    Year      Reviews     Month/Day/Year
  </code></pre>
  
  <p>This is after running it twice:</p>
  
  <pre><code>The following movie has been added to the directory:
  Movie Title (Year) Rating
  Stars: Reviews
  Last Watched: Month/Day/Year
  Movie Title    Rating    Year      Reviews     Month/Day/Year
                 Movie     Exception in thread "main" java.util.NoSuchElementException
  Title     Rating      Year/Reviews/Month
      at java.base/java.util.Scanner.throwFor(Scanner.java:858)
      at java.base/java.util.Scanner.next(Scanner.java:1381)
      at cs2410.assn3.directory.Directory.listMovies(Directory.java:71)
      at cs2410.assn3.directory.Directory.&lt;init&gt;(Directory.java:32)
      at cs2410.assn3.directory.Directory.main(Directory.java:79)
  </code></pre>
  
  <p>This is after running it 5 times:</p>
  
  <pre><code>The following movie has been added to the directory:
  Movie Title (Year) Rating
  Stars: Reviews
  Last Watched: Month/Day/Year
  Movie Title    Rating    Year      Reviews     Month/Day/Year
                 Movie     Title     Rating      Year/Reviews/Month
   Day Year      Movie     Title     Rating      Year/Reviews/Month
   Day Year      Movie     Title     Rating      Year/Reviews/Month
   Day Year      Movie     Title     Rating      Year/Reviews/Month
   Exception in thread "main" java.util.NoSuchElementException
      at java.base/java.util.Scanner.throwFor(Scanner.java:858)
      at java.base/java.util.Scanner.next(Scanner.java:1381)
      at cs2410.assn3.directory.Directory.listMovies(Directory.java:71)
      at cs2410.assn3.directory.Directory.&lt;init&gt;(Directory.java:32)
      at cs2410.assn3.directory.Directory.main(Directory.java:79)
  </code></pre>