Which is better: keep the InputStream file open for a long time, or open and close it a lot?

I wrote a small application in java that writes several lines to a text file every ten seconds or so. Is it better to initialize the input stream outside the loop and keep it open for a very long time, or open and close it every time I need to use it?

I don’t think it really matters in this example, since it is such a slow cycle, but I would like to know only about future calls. What about an identical script, but associated with a JDBC connection? ..

Many thanks.

+5
source share
2 answers

, , . , , open , - / . ( , ...)

JDBC . JDBC, / . ( , . JDBC .)

+3

, 10 . " ", , , , .

+1

All Articles