java try finally block to close stream

前端 未结 8 890
时光取名叫无心
时光取名叫无心 2020-12-05 17:25

I want to close my stream in the finally block, but it throws an IOException so it seems like I have to nest another try block in my finally<

8条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-05 17:55

    First thing I noticed in your code is curly bracket { } missing from your code if you look at it. also you need to initialize value of r to null so you need to pass null value to object at first so that if condition you have written can do not null condition check and lets you close the stream.

提交回复
热议问题