I\'d like to read data from a txt
file, but I get InputMismatchException
when I call nextDouble()
method. Even though I am using the
Blame the French locale: it uses comma as a decimal separator, so 1.9
fails to parse.
Replacing 1.9
with 1,9
fixes the problem (demo 1). If you would like to parse 1.9
, use Locale.US
instead of Locale.FRENCH
(demo 2).
A second problem in your code is the use of \\n
as the separator. You should use a single backslash, otherwise words that contain n
would break your parsing logic.