Я закрыл файл steam в try/finally, но анализ кода предупреждает меня:
- Возможная ошибка при закрытии FileOutputStream
- Возможная ошибка при закрытии PrintWriter
- Возможная ошибка при закрытии OutputStreamWriter
Как может случиться провал? Как я могу убедиться, что FileStream закрыт?
public void writeFile(String filepath)
{
BufferedWriter bw = null;
PrintWriter pw = null;
try {
File file = new File(filepath);
bfw = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file), "UTF-8"));
pw = new PrintWriter(bfw);
//do something
}catch(Exception e){
e.printStackTrace();
}
finally{
try{
bfw.close();
pw.close();
}catch(Exception e){
e.printStackTrace();
}
}
}