【发布时间】:2014-11-22 10:35:46
【问题描述】:
我有以下从文件中读取数据的函数。 如果我得到一个 IO 异常,我想完成这个函数的运行并继续这个程序中的下一个函数。
我应该在代码中添加什么?
我尝试将 continue 添加到 finnally 块,但出现错误“continue 不能在循环外使用”。
public void readFromFile() throws Exception
{
BufferedReader f= new BufferedReader(new FileReader("C:\\T.DAT"));
String l="";
try{
do{
l = f.readLine();
if(l != null)
{
Car a = new Car();
a.setFromLine(l);
alCars.add(a);
}
} while(line !=null);
}
catch (Exception e)
{
System.out.println("can't open file IO ERROR. program is continueing");
}
finally
{
f.close();
}
}
【问题讨论】:
标签: java exception bufferedreader filereader filenotfoundexception