I have code:
package package;
import java.io.BufferedReader;
import java.io.FileReader;
import java.util.ArrayList;
import java.util.List;
public class Test {
private List<Integer> liczby = new ArrayList<Integer>();
public void dodajLiczbe(int liczba) {
liczby.add(liczba);
}
public int wezLiczbe(int indeks) {
return liczby.get(indeks);
}
public int ileLiczb() {
return liczby.size();
}
public static void main(String[] args) {
Test w = new Test();
String nazwaPliku = "file.xyz";
try {
BufferedReader br = new BufferedReader(new FileReader(nazwaPliku));
String linia = null;
while ((linia = br.readLine()) != null) {
int liczba = Integer.parseInt(linia.trim());
w.dodajLiczbe(liczba);
}
} catch (Exception e) {
System.err.println("Wystapil blad przy wczytywaniu danych");
e.printStackTrace();
}
System.out.println("Wczytanych liczb: " + w.ileLiczb());
}
}
I'm trying to import my ASCII file, it has 150k lines and I have error (first line) in compile:
java.lang.NumberFormatException: For input string: "0.000 210 62"
at java.lang.NumberFormatException.forInputString(Unknown Source)
at java.lang.Integer.parseInt(Unknown Source)
at java.lang.Integer.parseInt(Unknown Source)
at package.Test.main(Test.java:33)
First column must be with ".". If you have a better option to do it, please tell me about that. First lines in file.xyz:
0.000 210 62
0.000 217 79
0.000 224 91
0.000 231 99
0.000 238 109