Say I have the following function
public static void myfunc(String filename) {
new FileInputStream(filename);
}
When I call that function, will there be resource leak because the FileInputStream is never released?
And future reference, is there a way I could verify that the resource hasn’t been released after the function has been called?
Yes, there is a resource leak. Most IDEs (such as Eclipse) will issue a warning indicating this. You should probably do something like along the lines of:
Or, if you’re using Java 7, you could use the try-with-resource statement.