LongBuffer: get(long[] dst) : LongBuffer « java.nio « Java by API






LongBuffer: get(long[] dst)

 
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.FileNotFoundException;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;

public class MainClass {
  public static void main(String[] args) {
    File aFile = new File("file.dat");
    FileInputStream inFile = null;

    try {
      inFile = new FileInputStream(aFile);
    } catch (FileNotFoundException e) {
      e.printStackTrace(System.err);
      System.exit(0);
    }
    FileChannel inChannel = inFile.getChannel();
    final int COUNT = 6;
    ByteBuffer buf = ByteBuffer.allocate(8 * COUNT);
    long[] data = new long[COUNT];
    try {
      while (inChannel.read(buf) != -1) {
        ((ByteBuffer) (buf.flip())).asLongBuffer().get(data);
        System.out.println();
        for (long prime : data)
          System.out.printf("%10d", prime);
        buf.clear();
      }
      System.out.println("\nEOF reached.");
      inFile.close();
    } catch (IOException e) {
      e.printStackTrace(System.err);
      System.exit(1);
    }
  }
}

           
         
  








Related examples in the same category

1.LongBuffer: clear()
2.LongBuffer: get()
3.ShortBuffer: hasRemaining()
4.LongBuffer: position()
5.LongBuffer: put(long l)
6.LongBuffer: put(long[] src, int offset, int length)
7.LongBuffer: remaining()