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

Here you can find the source of saveBytes(byte[] bytes, OutputStream out)

Description

this will not close the OutputStream.

Declaration

public static final void saveBytes(byte[] bytes, OutputStream out)
        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  ww.j a v  a  2 s.co  m

    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(byte[] bytes, File file, boolean append)
  2. writeFile(String fileName, byte[] content)
  3. writeFile(String fileName, byte[] datas, boolean overwrite)
  4. writeFile(String path, String fileName, byte[] datas, boolean overwrite)
  5. saveBytes(byte[] bytes, File file)
  6. saveBytes(byte[] bytes, String file)
  7. writeByteArrayToSD(String path, byte[] content, boolean create)