Java FileInputStream Read readFileBinaries(File file)

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

Description

read File Binaries

License

Open Source License

Declaration

public static byte[] readFileBinaries(File file) throws IOException 

Method Source Code

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

import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;

public class Main {
    public static byte[] readFileBinaries(File file) throws IOException {
        byte[] buffer = new byte[1024];
        ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
        FileInputStream inputStream = new FileInputStream(file);

        for (int readNum; (readNum = inputStream.read(buffer)) != -1;) {
            outputStream.write(buffer, 0, readNum);
        }/*from  w  w  w  .j  ava 2 s. c o  m*/

        inputStream.close();

        return outputStream.toByteArray();
    }
}

Related

  1. readFileAsInputStream(String fileName)
  2. readFileAsProperties(File file)
  3. readFileAsResource(String fileName)
  4. ReadFileAsUtf8String(String filePath)
  5. readFileAtOnce(final File file)
  6. readFileBinary(String filename)
  7. readFileBytes(File file)
  8. readFileBytes(File file)
  9. readFileBytes(String file)