Do I have to close FileInputStream?

后端 未结 8 792
广开言路
广开言路 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:08

    You either need to close(), or end your program.

    However you can run into confusing issues if you don't close the file as

    • sometimes test are run individually or a group of test are run in the same process. (So you could have a test which works one way but not the other)
    • you cannot rename or delete an open file.

    It is best practice to always close your resources which you are finished with them, however I see unit tests as scripts which don't always have to follow best practice.

提交回复
热议问题