Example
public class
ClassA {
private
FileInputStream stream;
public void
makeStream (File file) {
try
{
stream =
new
FileInputStream(file);
}
catch
(FileNotFoundException fnfe) {
//perform exception handling
}
//do something...
}
}
Solution
To avoid resource leaks, ensure that close() is invoked on every java.io.FileInputStream. Note: This rule applies to any form of FileInputStream constructor.
public class
ClassA {
private
FileInputStream stream;
public void
makeStream (File file) {
try
{
stream =
new
FileInputStream(file);
}
catch
(FileNotFoundException fnfe) {
//perform exception handling
}
//do something...
try
{
stream.close();
}
catch
(IOException ioe) {
//perform exception handling
}
}
}