Do I have to close FileInputStream?

后端 未结 8 731
广开言路
广开言路 2021-01-07 16:43

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

8条回答
  •  栀梦
    栀梦 (楼主)
    2021-01-07 17:20

    Recently, when I tried to refactor my code, I had to move the workbook creation to another method, and the FileInputStream is created in that method. That method creates a FileInputStream and returns a Workbook. But FileInputStream is not visible from the main method; so how will I close my FileInputStream at the end of main method? The answer is, you don't have to close FileInputStream, instead you just close the workbook, which internally closes FileInputStream. In short, it is incorrect to say that you must close FileInputStream no matter what.

提交回复
热议问题