do I need to surround fileInputStream.close with a try/catch/finally block? How is it done?

后端 未结 3 495
失恋的感觉
失恋的感觉 2021-01-05 06:16

I have the following Java Class that does one thing, fires out values from config.properties.

When it comes time to close the fileInputStream

3条回答
  •  感动是毒
    2021-01-05 06:52

    Because FileInputStream.close() throws an IOException, and the finally{} block doesn't catch exceptions. So you need to either catch it or declare it in order to compile. Eclipse's suggestion is fine; catch the IOException inside the finally{} block.

提交回复
热议问题