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

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

问题描述

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

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天全站免登陆