Java ByteBuffer Read readFileToByteBuffer(File file)

Here you can find the source of readFileToByteBuffer(File file)

Description

read File To Byte Buffer

License

Apache License

Declaration

static ByteBuffer readFileToByteBuffer(File file) throws IOException 

Method Source Code


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

import java.io.*;
import java.nio.ByteBuffer;

public class Main {
    static ByteBuffer readFileToByteBuffer(File file) throws IOException {
        RandomAccessFile randomAccessFile = null;
        try {//from   w w  w .j  a v  a  2  s  .co m
            randomAccessFile = new RandomAccessFile(file, "r");
            byte[] bytes = new byte[(int) randomAccessFile.length()];
            randomAccessFile.readFully(bytes);
            return ByteBuffer.wrap(bytes);
        } finally {
            if (randomAccessFile != null)
                randomAccessFile.close();
        }
    }
}

Related

  1. readCharsUTF8(ByteBuffer bb, int length)
  2. readCInt(ByteBuffer buffer)
  3. readCString(ByteBuffer buf, int len)
  4. readDERString(ByteBuffer buf)
  5. readDword(ByteBuffer buffer)
  6. readFixedLengthString(ByteBuffer buf, int length)
  7. readFixedLengthString(ByteBuffer byteBuffer, int size)
  8. readFixedPoint88(ByteBuffer bb)
  9. readFourByteInt(ByteBuffer buffer, int start)