I'm trying to read a double from a file but I have this exception: java.util.InputMismatchException. I've tried to do the useLocale(Locale.US) but it doesn't work.
This is my code
public static void main(String[] args){
System.out.println("Introduce the name of the file");
Scanner teclat = new Scanner(System.in);
teclat.useLocale(Locale.US);
Scanner fitxer = new Scanner(new File(teclat.nextLine()));
while(fitxer.hasNext()){
String origen=fitxer.next();
String desti=fitxer.next();
double distancia=fitxer.nextDouble();
System.out.println(origen);
System.out.println(desti);
System.out.println(distancia);
...
}
}
Now here is the content of the file that I have to read.
city1 city2 distance(km)
string string double
Barcelona Madrid 3005.15
Barcelona Valencia 750
Los_Angeles Toronto 8026.3
......