im trying to read a integer and two doubles from a text file. I wrote a shorter example demo of my problem.
import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;
public class Test {
public static void main(String[] args) {
int q = 0;
double w = 0, e = 0;
Scanner s = null;
try {
s = new Scanner(new File(args[0]));
while(s.hasNext()) {
q = s.nextInt();
w = s.nextDouble();
e = s.nextDouble();
}
System.out.println("1: " + q + "\n2: " + w + "\n3: " + e);
} catch(FileNotFoundException e1) {
e1.printStackTrace();
System.out.println(e1.getMessage());
} finally {
if(s != null) {
s.close();
}
}
}
}
It gives me a
Exception in thread "main" java.util.InputMismatchException
at java.util.Scanner.throwFor(Unknown Source)
at java.util.Scanner.next(Unknown Source)
at java.util.Scanner.nextDouble(Unknown Source)
at Test.main(Test.java:14)
I think my Scanner got a problem with reading the double, but I can't figure out why.
My text file contains:
3000 30.3 10.4