Java try/catch/finally best practices while acquiring/closing resources

后端 未结 8 1106
隐瞒了意图╮
隐瞒了意图╮ 2020-11-27 13:43

While working on a school project, I wrote the following code:

FileOutputStream fos;
ObjectOutputStream oos;
try {
    fos = new FileOutputStream(file);
             


        
8条回答
  •  我在风中等你
    2020-11-27 14:42

    You're doing it right. It bothers the crap out of me too. You should initialize those streams to null explicitly - it's common convention. All you can do is join the club and want for using.

提交回复
热议问题