Here you can find the source of writeStreamToFile(InputStream inputStream, File file)
public static void writeStreamToFile(InputStream inputStream, File file) throws IOException
//package com.java2s; /******************************************************************************* * Copyright (c) 2014 Gabriel Skantze.//from w ww .j a va2s. c om * All rights reserved. This program and the accompanying materials * are made available under the terms of the GNU Public License v3.0 * which accompanies this distribution, and is available at * http://www.gnu.org/licenses/gpl.html * * Contributors: * Gabriel Skantze - initial API and implementation ******************************************************************************/ 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 writeStreamToFile(InputStream inputStream, File file) throws IOException { FileOutputStream fout = new FileOutputStream(file); copyStream(inputStream, fout); fout.close(); } public static void copyStream(InputStream is, OutputStream os) throws IOException { byte[] b = new byte[256]; int r = 0; while ((r = is.read(b, 0, b.length)) > 0) { os.write(b, 0, r); } } }