Hold file handle open, or reopen as needed?
<p>I have a TCP server that handles a specific binary protocol.  Some requests include a large amount of data that is to be written to a file.  The server uses an NIO framework (netty), and has logic in it to deal with messages that have been broken up into multiple frames.</p>

<p>When an individual frame comes in, if the data in that frame is to be written to a file, then I open the file and write the data.  Even if the stream has not finished and I expect another frame with data to be appended to the same file, I currently close the file until I receive the next frame, at which point I reopen it and append the additional data.</p>

<p>I chose this method since it seemed the safest way to avoid leaving open file handles around and through some mistake not closing them, however, I am concerned that this will have negative performance implications.  Is it better (or best practices in this case) to leave the filehandles open (so keep a reference to an open FileOuputStream or Channel)?  Are there resource limit concerns with the number of open file handles?</p>
