Skip to content

Most visited

Recently visited

Added in API level 1


public interface ReadableByteChannel
implements Channel

Known Indirect Subclasses

A ReadableByteChannel is a type of Channel that can read bytes.

Read operations are synchronous on a ReadableByteChannel, that is, if a read is already in progress on the channel then subsequent reads will block until the first read completes. It is undefined whether non-read operations will block.


Public methods

abstract int read(ByteBuffer buffer)

Reads bytes from the channel into the given buffer.

Inherited methods

From interface java.nio.channels.Channel
From interface
From interface java.lang.AutoCloseable

Public methods


Added in API level 1
int read (ByteBuffer buffer)

Reads bytes from the channel into the given buffer.

The maximum number of bytes that will be read is the remaining number of bytes in the buffer when the method is invoked. The bytes will be read into the buffer starting at the buffer's current position.

The call may block if other threads are also attempting to read from the same channel.

Upon completion, the buffer's position is updated to the end of the bytes that were read. The buffer's limit is not changed.

buffer ByteBuffer: the byte buffer to receive the bytes.
int the number of bytes actually read.
AsynchronousCloseException if another thread closes the channel during the read.
ClosedByInterruptException if another thread interrupts the calling thread while the operation is in progress. The interrupt state of the calling thread is set and the channel is closed.
ClosedChannelException if the channel is closed.
IOException another I/O error occurs, details are in the message.
NonReadableChannelException if the channel was not opened for reading.
This site uses cookies to store your preferences for site-specific language and display options.


This class requires API level or higher

This doc is hidden because your selected API level for the documentation is . You can change the documentation API level with the selector above the left navigation.

For more information about specifying the API level your app requires, read Supporting Different Platform Versions.