inputMismatchException Java reading doubles from plain text file
Posted
by
user939287
on Stack Overflow
See other posts from Stack Overflow
or by user939287
Published on 2012-09-20T16:57:25Z
Indexed on
2012/09/20
21:38 UTC
Read the original article
Hit count: 147
java
Using
double variable = inputFile.nextDouble();
Gives the mismatch error and I can't figure out why... Anyone know what's up?
The input file is just a bunch of doubles like 5.0...
Okay here is the code snippet
String fileName;
Scanner scanner = new Scanner(System.in);
System.out.println("\nEnter file name that contains the matrix and vector: ");
fileName = scanner.nextLine();
Scanner inputFile = new Scanner(fileName);
double a1 = inputFile.nextDouble();
the input file is a plain text document .txt in this format
5.0 4.0 -3.0
4.0 2.0 5.0
6.0 5.0 -2.0
-13.0 4.0 12.0
I don't understand why it wouldn't take those as doubles...
As far as what its expecting the format of the file to be... I suppose binary? isn't that the default? I didn't specify in the code...
© Stack Overflow or respective owner