日期:2014-05-20  浏览次数:20738 次

字符串格式转换的问题
try {
bb = new BufferedReader(new InputStreamReader(
new FileInputStream(new File("F:\\测试2.txt"))));
String string = null;
while((string = bb.readLine()) != null) {
int ll = Integer.valueOf(string);
System.out.println(ll);
}
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch(IOException e) {
e.printStackTrace();
}finally {
try {
bb.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}

文件第一行存了1,第二行存了3,为什么抛出java.lang.NumberFormatException,没有其他的字符啊

------解决方案--------------------
字母l和数字1可不同哦,我觉得只有文件里面存放的不是数字字符才有可能出这个异常。