简体   繁体   中英

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? If not does it contradict the practise to close any I/O stream references after use?

System.in / out / err these classes are Instantiated by the JVM, not by us. Hence JVM will take care of closing them.

stdin , stdout and stderr are very much a Unix concept, but other operating systems (such as Windows) have copied the concept as well. 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.

System.in / out / err follow this strategy. So you could close them, but you don't have to, because they're special system resources.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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