Closing I / O Streams

What are the bad things that can happen when I don't close the stream?

Does the close operation work automatically?

Are all threads closed after the program exits?

Thanks in advance.

+3
source share
3 answers

Bad things that can happen when you do not close your threads:

  • you may run out of file descriptors
  • data that you think is written to disk can still be in the buffer (only)
  • files may be locked for other processes (platform dependent)
  • ...

Yes, the close operation always clears the stream.

, , . , FileOutputStream, FileInputStream / a Socket . FileOutputStream BufferedOutputStream, BufferedOutputStream / . , , BufferedOutputStream, FileOutputStream, .

+7

1) (, ). , .

2) ( , , ).

3)

+3

, close(), . , , .

+1

Source: https://habr.com/ru/post/1795492/


All Articles