Пример
public class
ClassA {
private
FileOutputStream stream;
public void
makeStream (File file) {
try
{
stream =
new
FileOutputStream(file);
}
catch
(FileNotFoundException fnfe) {
//perform exception handling
}
//do something...
}
}
Решение
Для того чтобы избежать утечки ресурсов, убедитесь, что close() инициализирован в каждом java.io.FileOutputStream. Примечание: это правило применимо к любой форме конструктора FileOutputStream.
public class
ClassA {
private
FileOutputStream stream;
public void
makeStream (File file) {
try
{
stream =
new
FileOutputStream(file);
}
catch
(FileNotFoundException fnfe) {
//perform exception handling
}
//do something...
try
{
stream.close();
}
catch
(IOException ioe) {
//perform exception handling
}
}
}