Android File to ByteBuffer Read readToByteBuffer(File f)

Here you can find the source of readToByteBuffer(File f)

Description

read To Byte Buffer

License

Open Source License

Declaration

public static ByteBuffer readToByteBuffer(File f) throws IOException 

Method Source Code

//package com.java2s;
//License from project: Open Source 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 readToByteBuffer(File f) throws IOException {
        return readToByteBuffer(f, (int) f.length());
    }/* www  .  j  a va2 s.c om*/

    public static ByteBuffer readToByteBuffer(File f, int toRead)
            throws IOException {
        ByteBuffer b = ByteBuffer.allocate(toRead);
        FileChannel fc = new FileInputStream(f).getChannel();
        fc.read(b);
        fc.close();
        b.flip();
        return b;
    }
}

Related

  1. bufferFile(File file)
  2. readToByteBuffer(File f, int toRead)