mardi 5 mai 2015

Using a scanner to extract data with delimiters by line

I am extracting data from a file. I am having trouble with using the delimiters while reading through the file.

My file is ordered like so:

0    Name    0
1    Name1   1

The structure is an integer, a tab (\t), a string, a tab (\t), another integer, and then a newline (\n).

I have tried to use a compound delimiter as referenced in this question: Java - Using multiple delimiters in a scanner

However, I am still getting an InputMismatch Exception when I run the following code:

while(readStations.hasNextLine()) { 
 327    tempSID = readStations.nextInt();
 328    tempName = readStations.next();
 329    tempLine = readStations.nextInt();
        //More code here
}

It calls this error on line two of the above code... I am not sure why, and help would be appreciated, Thanks.

The current output runs as such for the code:

Exception in thread "main" java.util.InputMismatchException
    ...stuff...
    at Metro.declarations(Metro.java:329)

Aucun commentaire:

Enregistrer un commentaire