Buffer: hasRemaining() : Buffer « java.nio « Java by API






Buffer: hasRemaining()

 
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());
  }
}

   
  








Related examples in the same category

1.Buffer: limit(int newLimit)
2.Buffer: remaining()