Java File Read via ByteBuffer readBinaryFile(File file)

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

Description

read Binary File

License

Open Source License

Declaration

static public ByteBuffer readBinaryFile(File file) throws IOException 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.io.BufferedInputStream;

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

import java.io.IOException;

import java.nio.ByteBuffer;

public class Main {
    static public ByteBuffer readBinaryFile(File file) throws IOException {
        ByteBuffer result = ByteBuffer.allocate((int) file.length());
        BufferedInputStream in = new BufferedInputStream(new FileInputStream(file));
        byte[] buf = new byte[1024];
        int len = 0;
        while ((len = in.read(buf)) != -1) {
            result.put(buf, 0, len);/*from   w w  w. j  av  a 2 s  .c o  m*/
        }
        in.close();
        result.flip();
        return result;
    }
}

Related

  1. read_file(File input)
  2. readAiffHeader(DataInputStream inStrm, FileChannel fc)
  3. readAndTransfer(final String dir)
  4. readAsByteArray(final InputStream source)
  5. readBigEndianWord(byte[] buf)
  6. readBinaryFileAsFloats(String fileName)
  7. readByte(String filePath)
  8. readBytes(File f)
  9. readBytes(final InputStream in, final int length)