I just want to know, we usually close streams at the end, but why don't we close System.out
PrintStream with System.out.close()
?
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
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.
回答2:
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.
回答3:
You can still flush() it, of course.