Map FileChannel to an IntBuffer and read from the IntBuffer : IntBuffer « File « Java Tutorial






import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.nio.IntBuffer;
import java.nio.channels.FileChannel;

public class MainClass {
  public static void main(String[] args) throws IOException {
    FileChannel fc = new FileInputStream(new File("temp.tmp")).getChannel();
    IntBuffer ib = fc.map(FileChannel.MapMode.READ_ONLY, 0, fc.size()).asIntBuffer();
    while (ib.hasRemaining())
      ib.get();
    fc.close();
  }
}








11.46.IntBuffer
11.46.1.Convert ByteBuffer to an IntBuffer
11.46.2.Use while loop to read an IntBuffer
11.46.3.Put integers to a mapped IntBuffer
11.46.4.Map FileChannel to an IntBuffer and read from the IntBuffer
11.46.5.Manipulating ints in a ByteBuffer with an IntBuffer