Java Dump Byte Array dumpFileIntoByteArray(File f)

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

Description

dump File Into Byte Array

License

Apache License

Declaration

public static byte[] dumpFileIntoByteArray(File f) throws IOException 

Method Source Code


//package com.java2s;
//License from project: Apache 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[] dumpFileIntoByteArray(File f) throws IOException {
        ByteArrayOutputStream byteStream = null;
        BufferedInputStream fileStream = null;
        try {/*from   w ww.j  a  v a 2  s .c  o  m*/
            byteStream = new ByteArrayOutputStream();
            fileStream = new BufferedInputStream(new FileInputStream(f));
            int data = -1;
            while ((data = fileStream.read()) != -1) {
                byteStream.write(data);
            }
        } catch (IOException e) {
            throw e;
        } finally {
            try {
                fileStream.close();
            } catch (Exception ex) {

            }
        }
        byte[] data = byteStream.toByteArray();
        return data;
    }
}

Related

  1. dumpByteArray(byte[] bytes)
  2. dumpBytes(PrintStream printStream, byte bytes[])
  3. dumpBytesAsString(ByteArrayOutputStream baos)
  4. dumpBytesToFile(byte[] bytes, String outputFile)
  5. dumpClass(String file, byte[] bytes)
  6. dumpHex(byte[] data)
  7. dumpHex(PrintStream out, byte[] data, int offset, int length)
  8. dumpHex(String _string, String _encoding)
  9. dumpHex(String value, String encoding)