This week's book giveaways are in the Refactoring and Agile forums.
We're giving away four copies each of Re-engineering Legacy Software and Docker in Action and have the authors on-line!
See this thread and this one for details.
Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Agile forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Hakim Benhamadouche
Greenhorn
Posts: 5
Java Linux Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic