Java:将整数从文件读取到数组中
File fil = new File("Tall.txt");
FileReader inputFil = new FileReader(fil);
BufferedReader in = new BufferedReader(inputFil);
int [] tall = new int [100];
String s =in.readLine();
while(s!=null)
{
int i = 0;
tall[i] = Integer.parseInt(s); //this is line 19
System.out.println(tall[i]);
s = in.readLine();
}
in.close();
我正在尝试使用文件“Tall.txt”将它们中包含的整数写入名为“tall”的数组中。它在某种程度上这样做,但是当我运行它时,它会引发以下异常(:
Exception in thread "main" java.lang.NumberFormatException: For input string: ""
at java.lang.NumberFormatException.forInputString(Unknown Source)
at java.lang.Integer.parseInt(Unknown Source)
at java.lang.Integer.parseInt(Unknown Source)
at BinarySok.main(BinarySok.java:19)
它究竟为什么这样做,我该如何删除它?正如我所看到的,我将文件作为字符串读取,然后将其转换为ints,这并不违法。