Here you can find the source of writeStreamToFile(InputStream stream, File file)
public static void writeStreamToFile(InputStream stream, File file)
//package com.java2s; //License from project: LGPL 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 void writeStreamToFile(InputStream stream, File file) { try {/*from w w w.jav a 2 s . com*/ OutputStream out = new FileOutputStream(file); byte[] buffer = new byte[1024]; int read; while ((read = stream.read(buffer)) > 0) { out.write(buffer, 0, read); } out.close(); stream.close(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } } }