Do I have to close FileInputStream?

Olaganathan.S picture Olaganathan.S · Feb 23, 2011 · Viewed 48.1k times · Source

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 using FileInputStream function.

FileInputStream fi=new FileInputStream("c:\\search.xls");
Workbook w=Workbook.getWorkbook(fi);
Sheet s=w.getSheet(0);

Is it necessary to close the Inputstream function? If it so please guide me with some codings.

Answer

asgs picture asgs · Feb 23, 2011

Yes, you need to close the inputstream if you want your system resources released back.

FileInputStream.close() is what you need.