Android Byte Array to File Save byte2file(byte[] data, String path)

Here you can find the source of byte2file(byte[] data, String path)

Description

bytefile

Declaration

public static void byte2file(byte[] data, String path) 

Method Source Code

//package com.java2s;

import java.io.File;

import java.io.FileOutputStream;

public class Main {

    public static void byte2file(byte[] data, String path) {
        if (null == data)
            return;
        if (data.length < 3 || path.equals(""))
            return;
        try {//from ww  w  .j  av a  2 s  .com
            FileOutputStream imageOutput = new FileOutputStream(new File(
                    path));
            imageOutput.write(data, 0, data.length);
            imageOutput.close();
            System.out.println("Make Picture success,Please find image in "
                    + path);
        } catch (Exception ex) {
            System.out.println("Exception: " + ex);
            ex.printStackTrace();
        }
    }

    static public boolean equals(byte[] a1, byte[] a2) {
        if ((a1 == null) || (a2 == null)) {
            return a1 == a2;
        }
        int nLength = a1.length;
        if (nLength != a2.length) {
            return false;
        }
        for (int i = 0; i < nLength; i++) {
            if (a1[i] != a2[i]) {
                return false;
            }
        }
        return true;
    }

    static public boolean equals(int[] a1, int[] a2) {
        if ((a1 == null) || (a2 == null)) {
            return a1 == a2;
        }
        int nLength = a1.length;
        if (nLength != a2.length) {
            return false;
        }
        for (int i = 0; i < nLength; i++) {
            if (a1[i] != a2[i]) {
                return false;
            }
        }
        return true;
    }
}

Related

  1. byteArrayToFile(byte[] bytes, String filePath)
  2. bytesToFile(byte[] bytes, String filePath)