File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes Scanner to read values from a file and Locale problems for nextDouble() Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Scanner to read values from a file and Locale problems for nextDouble()" Watch "Scanner to read values from a file and Locale problems for nextDouble()" New topic
Author

Scanner to read values from a file and Locale problems for nextDouble()

Karim Hamamouch
Greenhorn

Joined: Jun 07, 2011
Posts: 5

Hi everyone,

I'm quite puzzled as I need to read a configuration file in sequential mode (some lines are headers indicating the number of elements than we have elements themselves with their own attributes).
Fact is my default Locale uses ',' as decimal format separator (i.e: 12,3) while in my configuration files it's '.' (i.e: 12.3). By default it throws a java.util.InputMismatchException

I solved that by setting Locale.US to my scanner reference using the useLocale method but I'm wondering if it's the only choice I have (since I don't find methods to change just the decimal format separator).

Thanks for your explanations
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Scanner to read values from a file and Locale problems for nextDouble()
 
Similar Threads
NumberFormat question
JConsole csv time format?
DecimalFormat is not setting the format for is_IS Language
Setting decimalFormatSymbols
SCJP 5.0 objective 3