简体   繁体   English

Java System.in/out/err总是打开吗?

[英]Are Java System.in/out/err always open?

Javadoc says in , out and err are 'already open', I just wonder that do they close after program finishes? Javadoc说inouterr '已经打开',我只是想知道它们在程序完成后会关闭吗? If not does it contradict the practise to close any I/O stream references after use? 如果不是这样,是否与使用后关闭任何I / O流引用的做法相抵触?

System.in / out / err these classes are Instantiated by the JVM, not by us. System.in/out/err这些类是由JVM实例化的,而不是由我们实例化的。 Hence JVM will take care of closing them. 因此,JVM将负责关闭它们。

stdin , stdout and stderr are very much a Unix concept, but other operating systems (such as Windows) have copied the concept as well. stdinstdoutstderr在很大程度上是Unix概念,但是其他操作系统(例如Windows)也已经复制了该概念。 These are maintained by the system, and you usually don't close them. 这些由系统维护,通常不关闭它们。

However, you can close them, and you even have to close them when you fork() a program, which is the Unix way to have a program detach from the command line and run in the background, such as a daemon. 但是,您可以关闭它们,甚至在使用fork()程序时也必须关闭它们,这是Unix方式,可将程序与命令行分离并在后台运行,例如守护程序。

System.in / out / err follow this strategy. System.in / out / err遵循这一战略。 So you could close them, but you don't have to, because they're special system resources. 因此,您可以关闭它们,但不必这样做,因为它们是特殊的系统资源。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM