Java File to Byte Array getBytesFromFile(File file)

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

Description

get Bytes From File

License

Open Source License

Declaration

public static byte[] getBytesFromFile(File file) 

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[] getBytesFromFile(File file) {
        if (file == null) {
            return null;
        } else {/* www  . j  a  v  a 2 s  .  c om*/
            FileInputStream stream = null;
            ByteArrayOutputStream out = null;

            try {
                stream = new FileInputStream(file);
                out = new ByteArrayOutputStream(1000);
                byte[] b = new byte[1000];

                int n;
                while ((n = stream.read(b)) != -1) {
                    out.write(b, 0, n);
                }

                stream.close();
                out.close();
                byte[] var5 = out.toByteArray();
                return var5;
            } catch (IOException var19) {
                ;
            } finally {
                if (null != stream) {
                    try {
                        stream.close();
                    } catch (IOException var18) {
                        ;
                    }
                }

                if (null != out) {
                    try {
                        out.close();
                    } catch (IOException var17) {
                        ;
                    }
                }

            }

            return null;
        }
    }
}

Related

  1. getBytesFromFile(File f)
  2. getBytesFromFile(File file)
  3. getBytesFromFile(File file)
  4. getBytesFromFile(File file)
  5. getBytesFromFile(File file)
  6. getBytesFromFile(File file)
  7. getBytesFromFile(File file)
  8. getBytesFromFile(File file)
  9. getBytesFromFile(File file)