Here you can find the source of saveStreamToFile(InputStream in, File outFile)
public static void saveStreamToFile(InputStream in, File outFile) throws IOException
//package com.java2s; //License from project: Apache License import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; public class Main { public static void saveStreamToFile(InputStream in, File outFile) throws IOException { FileOutputStream out = null; try {//from w w w. ja v a 2s .c o m out = new FileOutputStream(outFile); byte[] buf = new byte[4096]; int bytes_read; while ((bytes_read = in.read(buf)) != -1) out.write(buf, 0, bytes_read); } finally { if (in != null) try { in.close(); } catch (IOException e) { e.printStackTrace(); } if (out != null) try { out.close(); } catch (IOException e) { e.printStackTrace(); } } } }