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)
为什么它会这样做,我该如何删除它?正如我所看到的,我将文件作为字符串读取,然后将其转换为整数,这不是非法的。