I am trying to read the following from a text file:
12
650 64 1
16 1024 2
My attempt:
import java.util.Scanner;
import java.io.*;
class Test{
public static void main(String[] args){
String filnavn = "regneklynge.txt";
Scanner innFil = null;
try {
File fil = new File(filnavn);
innFil = new Scanner(fil);
while (innFil.hasNextLine()) {
String linje = innFil.nextLine();
int tall = Integer.parseInt(linje);
System.out.println(tall);
}
} catch(FileNotFoundException e) {
System.out.println("Filen kunne ikke finnes");
}
}
}
The first number(12) Works fine, but then I get this
Exception in thread "main" java.lang.NumberFormatException: For input string: "650 64 1"