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

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

Description

save Bytes

Declaration

public static final void saveBytes(byte[] bytes, String 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  .ja  va2  s.  c  o  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. writeFile(String fileName, byte[] content)
  2. writeFile(String fileName, byte[] datas, boolean overwrite)
  3. writeFile(String path, String fileName, byte[] datas, boolean overwrite)
  4. saveBytes(byte[] bytes, File file)
  5. saveBytes(byte[] bytes, OutputStream out)
  6. writeByteArrayToSD(String path, byte[] content, boolean create)