我们为什么不在使用后关闭`System.out` Stream? [英] Why don't we close `System.out` Stream after using it?

查看:162
本文介绍了我们为什么不在使用后关闭`System.out` Stream?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只是想知道,我们通常在最后关闭流,但为什么我们不关闭 System.out PrintStream with System。 out.close()

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()?

推荐答案

如果你关闭它,你将无法再写到控制台,所以让我们在进程终止时将此任务留给VM。您应该只关闭您拥有或手动创建的流。 System.out 无法控制,因此请将其留给创作者处理。

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.

这篇关于我们为什么不在使用后关闭`System.out` Stream?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆