Android File to Byte Array Read getBytes(File file)

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

Description

get Bytes

Declaration

public static byte[] getBytes(File file) 

Method Source Code

//package com.java2s;

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

public class Main {
    public static byte[] getBytes(File file) {

        FileInputStream inputStream = null;
        byte[] fileContent = null;

        try {/*from ww  w .  j  ava2  s. com*/
            inputStream = new FileInputStream(file);
            fileContent = new byte[(int) file.length()];
            inputStream.read(fileContent);

        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            try {
                inputStream.close();
            } catch (Exception ex) {
                ex.printStackTrace();
            }
        }
        return fileContent;
    }
}

Related

  1. getBytes(File file)
  2. getBytesFromFile(File file)
  3. getBytesFromFile(File file, long startPostion, long numberOfBytesToRead)
  4. getFileAsByteArray(File file)