我有以下函數從文件讀取數據。 如果我得到一個IO異常,我想完成這個函數的運行並繼續執行這個程序中的下一個函數。JAVA - 文件沒有找到異常後繼續
我應該添加什麼代碼?
我試圖添加繼續到finnally塊,但我得到錯誤「繼續不能在循環之外使用」。
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();
}
}
不,如果沒有「返回」它退出程序... – user3557163 2014-11-22 10:51:14