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()
?
Asked
Active
Viewed 3,199 times
20

Eng.Fouad
- 115,165
- 71
- 313
- 417
3 Answers
24
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.

Darin Dimitrov
- 1,023,142
- 271
- 3,287
- 2,928
17
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.

Raedwald
- 46,613
- 43
- 151
- 237

ratchet freak
- 47,288
- 5
- 68
- 106
-
1@henning `free` then or in a C++ adage – ratchet freak Sep 17 '11 at 22:31