Here you can find the source of copyStreamToFile(InputStream stream, File file)
Parameter | Description |
---|---|
stream | a parameter |
file | a parameter |
Parameter | Description |
---|
public static void copyStreamToFile(InputStream stream, File file) throws IOException
//package com.java2s; // BSD License (http://www.galagosearch.org/license) import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; public class Main { /**// w ww. j a v a 2s.c o m * Copies the data from the InputStream to a file, then closes both when * finished. * * @param stream * @param file * @throws java.io.IOException */ public static void copyStreamToFile(InputStream stream, File file) throws IOException { FileOutputStream output = new FileOutputStream(file); final int oneMegabyte = 1 * 1024 * 1024; byte[] data = new byte[oneMegabyte]; while (true) { int bytesRead = stream.read(data); if (bytesRead < 0) { break; } output.write(data, 0, bytesRead); } stream.close(); output.close(); } }