我是新来的例外,还没有在大学里覆盖他们,所以仍然在学习他们。我试过这个,它似乎工作,但似乎并不“正确”。处理异常后再次尝试方法的正确方法是什么?处理异常后再次尝试方法的正确方法是什么?
public static void openCSV(String file) {
FileInputStream fis;
try {
fis = new FileInputStream(file);
} catch (FileNotFoundException e) { //fnf, probably not downloaded yet.
downloadCSV(file); //Download it and try again.
try {
fis = new FileInputStream(file);
} catch (FileNotFoundException e) {
// OK, something else is the problem.
}
}
}
'fis.close()'应该在另一个'try/catch'块中。 – BalusC 2010-01-06 17:59:24
BalusC是正确的。编辑。 – 2010-01-06 18:23:56