Android Byte Array Save to File saveBytes(byte[] bytes, File file)

Here you can find the source of saveBytes(byte[] bytes, File file)

Description

save Bytes

Declaration

public static final void saveBytes(byte[] bytes, File file)
            throws IOException 

Method Source Code

//package com.java2s;
import java.io.File;

import java.io.FileOutputStream;
import java.io.IOException;

import java.io.OutputStream;

public class Main {
    public static final void saveBytes(byte[] bytes, String file)
            throws IOException {
        saveBytes(bytes, new File(file));
    }//from  w  w  w. j ava2  s . com

    public static final void saveBytes(byte[] bytes, File file)
            throws IOException {
        file.createNewFile();
        FileOutputStream out = new FileOutputStream(file);
        try {
            saveBytes(bytes, out);
        } catch (IOException e) {
            throw e;
        } finally {
            out.close();
        }
    }

    /** this will not close the OutputStream. it may need for further use */
    public static final void saveBytes(byte[] bytes, OutputStream out)
            throws IOException {
        out.write(bytes);
        out.flush();
    }
}

Related

  1. writeBytes(File file, boolean append, byte[] bytes)
  2. writeBytes(byte[] bytes, File file, boolean append)
  3. writeFile(String fileName, byte[] content)
  4. writeFile(String fileName, byte[] datas, boolean overwrite)
  5. writeFile(String path, String fileName, byte[] datas, boolean overwrite)
  6. saveBytes(byte[] bytes, OutputStream out)
  7. saveBytes(byte[] bytes, String file)
  8. writeByteArrayToSD(String path, byte[] content, boolean create)