Java File to Byte Array getBytesFromFile(String file)

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

Description

get Bytes From File

License

Open Source License

Declaration

public static byte[] getBytesFromFile(String file) throws Exception 

Method Source Code

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

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

public class Main {
    public static byte[] getBytesFromFile(String file) throws Exception {
        byte[] res = null;
        try {//from  www.j a v  a  2 s . c  o m
            File f = new File(file);
            FileInputStream fin = new FileInputStream(f);
            res = new byte[fin.available()];
            int b = fin.read(res);
            if (b != res.length) {
                return null;
            }
            fin.close();
            return res;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }
}

Related

  1. getBytesFromFile(File file)
  2. getBytesFromFile(File file)
  3. getBytesFromFile(File file)
  4. getBytesFromFile(File inputFile)
  5. getBytesFromFile(final File file)
  6. getBytesFromFile(String fileName)
  7. getBytesFromFile(String filename)
  8. getBytesFromFile(String filename)
  9. getBytesFromFile(String filename)