Here you can find the source of inputStreamToFile(InputStream in, File file)
public static void inputStreamToFile(InputStream in, File file) throws Exception
//package com.java2s; //License from project: Apache License import java.io.BufferedOutputStream; import java.io.File; import java.io.FileOutputStream; import java.io.InputStream; import java.util.logging.Logger; public class Main { private static final Logger LOG = Logger.getLogger("Utils"); public static void inputStreamToFile(InputStream in, File file) throws Exception { BufferedOutputStream out = null; byte[] b = new byte[8192]; try {/*from w ww . j a va 2s .com*/ out = new BufferedOutputStream(new FileOutputStream(file)); for (int n; (n = in.read(b)) != -1;) { out.write(b, 0, n); } } catch (Exception e) { LOG.severe(e.getMessage()); } finally { if (out != null) { out.flush(); out.close(); } if (in != null) { in.close(); } } } }