Here you can find the source of inputStream2File(InputStream in, File file)
public static void inputStream2File(InputStream in, File file) 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; import java.io.OutputStream; public class Main { public static void inputStream2File(InputStream in, File file) throws IOException { OutputStream os = new FileOutputStream(file); int bytesRead = 0; byte[] buffer = new byte[8192]; try {/*from www . j a v a2 s . c o m*/ while ((bytesRead = in.read(buffer, 0, 8192)) != -1) { os.write(buffer, 0, bytesRead); } } finally { try { os.close(); } catch (IOException e) { e.printStackTrace(); } try { in.close(); } catch (IOException e) { e.printStackTrace(); } } } }