Java FileInputStream Read readFileBytes(String file)

Here you can find the source of readFileBytes(String file)

Description

read File Bytes

License

Creative Commons License

Declaration

public static byte[] readFileBytes(String file) throws IOException 

Method Source Code


//package com.java2s;
//License from project: Creative Commons License 

import java.io.*;

public class Main {
    public static byte[] readFileBytes(String file) throws IOException {

        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        BufferedInputStream httpIn = new BufferedInputStream(new FileInputStream(file));
        byte[] buffer = new byte[1024];
        int n;// ww w. j  a v a2  s  . c o  m

        while ((n = httpIn.read(buffer)) != -1)
            baos.write(buffer, 0, n);

        httpIn.close();
        return baos.toByteArray();

    }
}

Related

  1. readFileAtOnce(final File file)
  2. readFileBinaries(File file)
  3. readFileBinary(String filename)
  4. readFileBytes(File file)
  5. readFileBytes(File file)
  6. readFileBytes(String filename)
  7. readFileBytes(String fileName)
  8. readFileBytes(String filePath)
  9. readFileEndAsString(File file, int size_limit)