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」的數組中。爲此,它會在一定程度上,也當我運行它,它會引發以下異常(?:Java:從一個文件讀取整數到一個數組
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)
正是它爲什麼這樣做,我怎麼刪除它,因爲我看到它,我讀了文件作爲字符串,然後將其轉換爲整數,這是不是非法
BTW,你應該宣佈 「我」 之外while循環。如果不是,您將總是在您的數組的索引0處插入整數。 – 2008-11-20 01:23:45
順便說一句,評論「這是第19行」是「有史以來最佳評論」的候選人。你正在使用什麼IDE? – 2009-04-27 08:28:50
我完全不知道那是怎麼到的。我想我從某個地方拿走了部分代碼,顯然這些評論來了。很可能是 – Northener 2009-05-10 04:12:05