Reputation: 6543
I am learning about I/O, Files and Sockets and i don't understand the meaning of this sentence
read will not always fill a buffer
What does it mean? Anyone has some explanation for me?
Upvotes: 1
Views: 530
Reputation: 311023
It will block until at least one byte is available, and return the number of bytes that can be read at that point without blocking again. See the Javadoc.
Upvotes: 1
Reputation: 8312
The read() method accepts a byte-array that it will fill with from the stream or reader.
If there is not enough data available to fill the buffer, it can either
The standard implementation does a mixtures of both: It waits until at least one byte is available.
Note: The second case implies that read() may return without any data at all.
Upvotes: 1
Reputation: 33544
"read will not always fill a buffer"
The above sentence means that Buffer
has a certain size
which is AutoFlushed when filled, But suppose the data to be read into the Buffer is not enough to fill the Buffer... Then you need to manually flush it.
For futher details read the SCJP Programmer guide
by Kathy Sierra or Thinking in Java's
IO chapter.
Upvotes: 2