Here you can find the source of copyStreamToFile(InputStream in, File out)
public static void copyStreamToFile(InputStream in, File out) 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 copyStreamToFile(InputStream in, File out) throws IOException { FileOutputStream fos = null; try {/*from w w w.j a v a 2s . co m*/ fos = new FileOutputStream(out); byte[] buf = new byte[1024]; int i = 0; while ((i = in.read(buf)) != -1) { fos.write(buf, 0, i); } } finally { if (in != null) { try { in.close(); } catch (IOException e) { } } if (fos != null) { try { fos.close(); } catch (IOException e) { } } } } }