开发者

Why don't we close `System.out` Stream after using it?

开发者 https://www.devze.com 2023-04-05 09:13 出处:网络
I just want to know, we usually cl开发者_如何学运维ose streams at the end, but why don\'t we close System.out PrintStream with System.out.close()?If you close it you will no longer be able to write to

I just want to know, we usually cl开发者_如何学运维ose streams at the end, but why don't we close System.out PrintStream with System.out.close()?


If you close it you will no longer be able to write to the console, so let's leave this task to the VM when the process terminates. You should only close streams that you own or have manually created. System.out is out of your control, so leave it to the creator to take care of.


because we didn't open it the VM did and it's his job to close it unless otherwise documented

it's similar to the C++ adage of I don't own it, don't delete it.


You can still flush() it, of course.

0

精彩评论

暂无评论...
验证码 换一张
取 消