mercredi 29 avril 2015

While loop runs once?

The split function does not work. for the last print statement, it gives me an arrayoutofbound error. Any help?

 while (inFile.hasNext())
            {
               String clean = inFile.nextLine();
               String[] nm = clean.split(",");
               for (int i = 0; i < nm.length; i++)
                {
                    System.out.println("at index "+ i +" string is "+nm[i]);
                }
               System.out.print("at index"+2+"Strin"+nm[3]);
            }

text file :

input1,2,3,4,5
input2,2,3,4,5
input3,3,4,5,6
input4,3,4,5,6
input5,3,4,5,6

Aucun commentaire:

Enregistrer un commentaire