Here you can find the source of inputStreamToFile(InputStream stream, File file)
public static void inputStreamToFile(InputStream stream, File file) throws IOException
//package com.java2s; import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; public class Main { public static void inputStreamToFile(InputStream stream, File file) throws IOException { FileOutputStream output = null; try {/*from w w w. j a va 2 s .c o m*/ output = new FileOutputStream(file); copyStream(stream, output); } finally { if (output != null) { output.close(); } } } /** * Copies the data from one input stream to an * output stream. * * @param stream A readable data stream * @param output A writable data stream to write the data. * @throws IOException An I/O error occurred. */ public static void copyStream(InputStream stream, OutputStream output) throws IOException { byte[] buffer = new byte[8192]; while (true) { int count = stream.read(buffer, 0, buffer.length); if (count < 0) { break; } output.write(buffer, 0, count); } } }