When does a stream close if its not closed manually?

后端 未结 6 2036
一个人的身影
一个人的身影 2021-01-04 10:27

I would like to know when does a stream close if its not closed manually. By this I mean, will the stream be closed if the scope of its reference is no more?

Conside

6条回答
  •  生来不讨喜
    2021-01-04 11:18

    I don't think that the JVM spec makes any guarantee about that. You really are supposed to finally close these resources.

    When the process ends, the operating system will release all resources associated to it (including memory, file handles, and network sockets).

    There are OS facilities to check about open files and streams, such as lsof.

提交回复
热议问题