FileChannel: read(ByteBuffer dst)
abstract int read(ByteBuffer dst)
- Reads a sequence of bytes from this channel into the given buffer.
import java.io.FileInputStream;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;
public class Main {
private static final int BSIZE = 1024;
public static void main(String[] args) throws Exception {
FileChannel fc = new FileInputStream("data.txt").getChannel();
ByteBuffer buff = ByteBuffer.allocate(BSIZE);
fc.read(buff);
buff.flip();
while (buff.hasRemaining())
System.out.print((char) buff.get());
}
}
Home
Java Book
File Stream
Java Book
File Stream
FileChannel:
- FileChannel
- FileChannel.MapMode.READ_WRITE
- FileChannel: close()
- FileChannel: lock(long position, long size, boolean shared)
- FileChannel: map(MapMode mode, long position, long size)
- FileChannel: position()
- FileChannel: position(long newPosition)
- FileChannel: read(ByteBuffer dst)
- FileChannel: size()
- FileChannel: transferFrom(ReadableByteChannel src, long position, long count)
- FileChannel: transferTo(long position, long count, WritableByteChannel target)
- FileChannel: tryLock()
- FileChannel: write(MappedByteBuffer buffer)