Here you can find the source of writeFile(InputStream in, File file)
Parameter | Description |
---|---|
in | The Input Stream. |
file | File to save. |
Parameter | Description |
---|---|
IOException | an exception |
public static void writeFile(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; public class Main { /**/*from ww w . j av a 2 s.c o m*/ * Saves an Input Stream to a file. * * @param in The Input Stream. * @param file File to save. * @throws IOException */ public static void writeFile(InputStream in, File file) throws IOException { FileOutputStream out = new FileOutputStream(file); byte[] buffer = new byte[1024]; int len = in.read(buffer); while (len != -1) { out.write(buffer, 0, len); len = in.read(buffer); } out.close(); in.close(); } }