Here you can find the source of saveFile(File f, InputStream stream)
Parameter | Description |
---|---|
f | a parameter |
stream | a parameter |
Parameter | Description |
---|---|
Exception | an exception |
public static void saveFile(File f, InputStream stream) throws Exception
//package com.java2s; //License from project: Apache License import java.io.File; import java.io.FileOutputStream; import java.io.InputStream; import java.io.OutputStream; public class Main { /**/* w w w . j a va 2s . c om*/ * saveFile * Saves a given input stream to a specified file * @param f * @param stream * @throws Exception */ public static void saveFile(File f, InputStream stream) throws Exception { OutputStream out = new FileOutputStream(f); int read = 0; byte[] bytes = new byte[1024]; while ((read = stream.read(bytes)) != -1) { out.write(bytes, 0, read); } stream.close(); out.flush(); out.close(); } }