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  

FileChannel:
  1. FileChannel
  2. FileChannel.MapMode.READ_WRITE
  3. FileChannel: close()
  4. FileChannel: lock(long position, long size, boolean shared)
  5. FileChannel: map(MapMode mode, long position, long size)
  6. FileChannel: position()
  7. FileChannel: position(long newPosition)
  8. FileChannel: read(ByteBuffer dst)
  9. FileChannel: size()
  10. FileChannel: transferFrom(ReadableByteChannel src, long position, long count)
  11. FileChannel: transferTo(long position, long count, WritableByteChannel target)
  12. FileChannel: tryLock()
  13. FileChannel: write(MappedByteBuffer buffer)