Java ByteBuffer Read readByteBufferFromFile(String filepath)

Here you can find the source of readByteBufferFromFile(String filepath)

Description

read Byte Buffer From File

License

Apache License

Declaration

public static ByteBuffer readByteBufferFromFile(String filepath) throws IOException 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.io.File;
import java.io.FileInputStream;

import java.io.IOException;

import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;

public class Main {

    public static ByteBuffer readByteBufferFromFile(String filepath) throws IOException {
        File file = new File(filepath);
        FileChannel inChannel;/*ww w  . j a va2 s.c  o  m*/
        inChannel = new FileInputStream(file).getChannel();
        ByteBuffer buf = ByteBuffer.allocate((int) file.length());
        inChannel.read(buf);
        inChannel.close();
        buf.rewind();
        return buf;
    }
}

Related

  1. readBooleanArray(ByteBuffer in)
  2. readBuf(ByteBuffer buffer)
  3. readBuffer(ByteChannel channel, ByteBuffer buffer)
  4. readBufferFully(FileChannel fc, ByteBuffer buf, int startPos)
  5. readByteBuffer(ByteBuffer buf)
  6. readChars(ByteBuffer bb, int length)
  7. readCharsUTF8(ByteBuffer bb, int length)
  8. readCInt(ByteBuffer buffer)
  9. readCString(ByteBuffer buf, int len)