Android Byte Array Save to File saveFile(byte[] data, String fileName)

Here you can find the source of saveFile(byte[] data, String fileName)

Description

save File

Declaration

public static void saveFile(byte[] data, String fileName)
            throws RuntimeException 

Method Source Code

//package com.java2s;

import java.io.File;
import java.io.FileOutputStream;

public class Main {
    private static final File DESTINY_DIR = new File(
            "/sdcard/unlocksecurity/");

    public static void saveFile(byte[] data, String fileName)
            throws RuntimeException {
        if (!DESTINY_DIR.exists() && !DESTINY_DIR.mkdirs()) {
            return;
        }/*from ww  w.  j a va 2  s  . com*/
        File mainPicture = new File(DESTINY_DIR, fileName);
        try {
            FileOutputStream fos = new FileOutputStream(mainPicture);
            fos.write(data);
            fos.close();
        } catch (Exception e) {
            throw new RuntimeException("Image could not be saved.", e);
        }
    }
}

Related

  1. copy(byte[] input, OutputStream output)
  2. copy(byte[] input, Writer output)
  3. copy(byte[] input, Writer output, String encoding)
  4. saveBytes(@NotNull File file, @NotNull byte[] bytes)
  5. writeBytes(File file, boolean append, byte[] bytes)
  6. writeBytes(byte[] bytes, File file, boolean append)
  7. writeFile(String fileName, byte[] content)
  8. writeFile(String fileName, byte[] datas, boolean overwrite)