Java FileInputStream Read readFile(File file)

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

Description

read File

License

Open Source License

Declaration

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

Method Source Code


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

import java.io.BufferedInputStream;

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

import java.io.IOException;

public class Main {
    public static byte[] readFile(File file) throws IOException {
        byte[] data = null;
        FileInputStream fis = new FileInputStream(file);
        BufferedInputStream bis = new BufferedInputStream(fis);
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        byte[] buffer = new byte[1024];
        int br;/*w ww  . j  av  a 2 s  .  com*/
        while ((br = bis.read(buffer)) > 0) {
            baos.write(buffer, 0, br);
        }
        baos.close();
        bis.close();
        data = baos.toByteArray();
        return data;
    }
}

Related

  1. readFile(File f)
  2. readFile(File f)
  3. readFile(File f)
  4. readFile(File f, int fetchLength, byte[] bytes)
  5. readFile(File f, int iChunkSize)
  6. readFile(File file)
  7. readFile(File file)
  8. readFile(File file)
  9. readFile(File file)