Here you can find the source of saveToFile(byte[] data, String filename)
public static boolean saveToFile(byte[] data, String filename) throws IOException
//package com.java2s; //License from project: Open Source License import java.io.ByteArrayInputStream; import java.io.File; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; public class Main { public static boolean saveToFile(byte[] data, String filename) throws IOException { OutputStream os = null;/*ww w. j a v a2 s. c om*/ ByteArrayInputStream bin = null; try { if (data != null) { bin = new ByteArrayInputStream(data); os = new FileOutputStream(filename); byte[] bytes = new byte[1024]; int c; while ((c = bin.read(bytes)) != -1) { os.write(bytes, 0, c); } os.flush(); return true; } ; } catch (IOException e) { e.printStackTrace(); throw e; } finally { try { if (os != null) { os.close(); os = null; } } catch (Exception e) { } try { if (bin != null) { bin.close(); bin = null; } } catch (Exception e) { } } return false; } public static boolean saveToFile(InputStream ins, String filename) throws IOException { try { OutputStream out = new FileOutputStream(new File(filename)); int read = 0; byte[] bytes = new byte[1024]; while ((read = ins.read(bytes)) != -1) { out.write(bytes, 0, read); } out.flush(); out.close(); return true; } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return false; } }