开发者

Having issues reading Long types from a textfile using Java scanner

I'm trying to read a long type from a text file using Scanner in Java. I get the following error:

Exception in thread "main" java.util.InputMismatchException
at java.util.Scanner.throwFor(Scanner.java:840)
at java.util.Scanner.next(Scanner.java:1461)
at java.util.Scanner.nextLong(Scanner.java:2196)
at java.util.Scanner.nextLong(Scanner.java:2156)
at Project.main(Project.java:119)

Which correlates to this line:

strLine = (long) in.nex开发者_如何学运维tLong();

If I do in.next() it will work, but I need to store the info as a long, not as a String. The exact number it's getting mad at reading is: 3.20e11

Anyone know how to fix this? Thanks in advance!


3.20e11's double.

You should do:

strLine = (long) in.nextDouble();


It thinks 3.20e11 is a double, which is why you get the input mismatch. Try the input as 320000000000 and it will work.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜