How do you decide what byte[] size to use for InputStream.read()?

后端 未结 5 1640
生来不讨喜
生来不讨喜 2020-12-05 02:42

When reading from InputStreams, how do you decide what size to use for the byte[]?

int nRead;
byte[] data = new byte[16384]; // <-- this number is the o         


        
5条回答
  •  不知归路
    2020-12-05 02:45

    By using the available() method in the InputStream class. From the Javadoc:

    Returns the number of bytes that can be read (or skipped over) from this input stream without blocking by the next caller of a method for this input stream. The next caller might be the same thread or or another thread.

提交回复
热议问题