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