Here you can find the source of copyStreamToFile(InputStream inputStream, File outputFile)
public static File copyStreamToFile(InputStream inputStream, File outputFile) throws Exception
//package com.java2s; /**/*from w ww . j a v a2 s . c om*/ * License: https://github.com/votingsystem/votingsystem/wiki/Licencia */ import java.io.*; public class Main { private static final int BUFFER_SIZE = 4096; public static File copyStreamToFile(InputStream inputStream, File outputFile) throws Exception { OutputStream outputStream = new FileOutputStream(outputFile); byte[] buf = new byte[BUFFER_SIZE]; int len; while ((len = inputStream.read(buf)) > 0) { outputStream.write(buf, 0, len); } outputStream.close(); inputStream.close(); return outputFile; } public static File copyStreamToFile(InputStream inputStream) throws Exception { File outputFile = File.createTempFile("streamToFile", ".html"); outputFile.deleteOnExit(); OutputStream outputStream = new FileOutputStream(outputFile); byte[] buf = new byte[BUFFER_SIZE]; int len; while ((len = inputStream.read(buf)) > 0) { outputStream.write(buf, 0, len); } outputStream.close(); inputStream.close(); return outputFile; } }