I am working as a trainee in Test Automation. I am working with creating Junit code with Eclipse and run using Eclipse. In that I am retriving the datas from excel sheet usi
Yes! you should always release the resources once after you are done with them. Java has a powerful mechanism for Garbage Collection(note that it is different thing compare to resource management/leaks.) So a Garbage collector can not determine that if you need the resource in future or not? Failing to release resources may cause issues like- Denial of services, poor performance .
As already answered but another effort less way is try with resources
try (FileInputStream fi = new FileInputStream("c:\\search.xls")) {
//do something with fi.
//fi.getChannel() ;
} catch(IOException e) {
// exception handling.
} finally {
// some statements for finally.
}
Now you don't need to explicitly call fi.close() method.