CitireFisier.java
public class CitireFisier {
public static void main(String[] args) {
File f = new File("fisier.txt");
Scanner scn = null;
try {
scn = new Scanner(f);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
int size = scn.nextInt();
System.out.println("val is " + size);
double var = scn.nextDouble();
System.out.println("val is " + var);
}
}
Output
val is 3
Exception in thread "main" java.util.InputMismatchException
at java.util.Scanner.throwFor(Unknown Source)
at java.util.Scanner.next(Unknown Source)
fisier.txt
3
0.1 0.7 0.2 init g
0.0 0.0 1.0 g y
0.0 0.0 1.0 g y
nextDouble()
receive the error but 0.1 is double
!