Doing my first steps with Java, here's my problem:
1.) the rawData.txt
can be read:
import java.util.Scanner;
import java.io.File;
import java.io.FileNotFoundException;
import static java.lang.System.out;
class ReadAndWrite {
public static void main(String args[])
throws FileNotFoundException {
Scanner diskScanner = new Scanner(new File("rawData.txt"));
String diskString;
diskString = diskScanner.nextLine();
out.println(diskString);
diskScanner.close();
}
}
The result in eclipse console is :
>19.5 5
So I guess the content can be read.
But: nextDouble()
and nextInt()
won't work:
import java.util.Scanner;
import java.io.File;
import java.io.FileNotFoundException;
class ReadAndWrite {
public static void main(String args[])
throws FileNotFoundException {
Scanner diskScanner = new Scanner(new File("rawData.txt"));
double unitPrice, quantity;
unitPrice = diskScanner.nextDouble();
quantity = diskScanner.nextInt();
[...]
diskScanner.close();
}
}
The error message from console is:
Exception in thread "main" java.util.InputMismatchException
at java.util.Scanner.throwFor(Scanner.java:864)
at java.util.Scanner.next(Scanner.java:1485)
at java.util.Scanner.nextDouble(Scanner.java:2413)
at ReadAndWrite.main(ReadAndWrite.java:16)
So what can I do to understand the problem?