Using substrings while reading file data
<p>Last night I asked a question like this, I'm not sure what's happening and I have encountered another problem so here goes:</p>

<p>My instructor has given my class a project a program that reads a file, reads each letter and then prints out the amount of hits, outs, walks and sacrifice flies that each line has. I posted some more info in my <a href="http://stackoverflow.com/questions/7828724/reading-statistics-from-a-file">original question</a> about this topic.
I have rewritten the code in chance that I would better my chances of getting the program to work. I learned about what substrings are and a bit more about tokens and came together with this program:</p>

<pre><code>import java.util.Scanner;
import java.io.*;

public class BaseballStats
{
  public static void main(String[]args) throws IOException
  {
    Scanner fileScan, lineScan;
    String fileName;
    int oCount = 0, hCount = 0, sCount = 0, wCount = 0;
    Scanner scan = new Scanner(System.in);

    System.out.print("Enter the name of the input file: ");
    fileName = scan.nextLine();
    fileScan = new Scanner(new File(fileName));

    while (fileScan.hasNext())
    {
      lineScan = new Scanner (fileName);
      lineScan.useDelimiter(",");

      String input = lineScan.nextLine();
      int point =(input.indexOf(","));

      String name = input.substring(0,point);
      String records = input.substring(point,input.length());

      for (int i = 0; i &lt; records.length(); i++)
      {
        if (records.charAt(i) == 's')
          sCount++;
        else if (records.charAt(i) == 'o')
          oCount++;
        else if (records.charAt(i) == 'h')
          hCount++;
        else if (records.charAt(i) == 'w')
          wCount++;
      }// end of for loop
      System.out.printf("Name: %s. Hits: %d. Outs: %d. Walks: %d. Sacrifice flies: %d.", name, hCount, oCount, wCount, sCount);
      System.out.println();

  }//end of while loop

 }//end of main
}// end
</code></pre>

<p>The program runs fine, but after I enter in stats.dat(The file that is supposed to be reading), I get the following exception error:</p>

<pre><code>java.lang.StringIndexOutOfBoundsException: String index out of range: -1
at java.lang.String.substring(Unknown Source)
at BaseballStats.main(BaseballStats.java:25)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at edu.rice.cs.drjava.model.compiler.JavacCompiler.runCommand(JavacCompiler.java:271)
</code></pre>

<p>It points to line 25, which is the</p>

<pre><code>String name = input.substring(0,point);
</code></pre>

<p>line. I have been stumped on this, am I missing something?</p>

<p>Note: I have read Adamski's suggestion on the original question. I tried to follow it but as I'm new to java I'm having a hard time understanding encapsulation, specifically the setter and getter methods. I figured it would be best to leave them alone for now until next chapter, where my class explains them.</p>
