Here you can find the source of copyStream(InputStream copyFrom, File copyTo)
Parameter | Description |
---|---|
copyFrom | a parameter |
copyTo | a parameter |
Parameter | Description |
---|---|
IOException | an exception |
public static void copyStream(InputStream copyFrom, File copyTo) throws IOException
//package com.java2s; //License from project: Open Source License import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; public class Main { /**//from ww w . j a va 2s .c o m * Copy an input stream to a file location * * @param copyFrom * @param copyTo * @throws IOException */ public static void copyStream(InputStream copyFrom, File copyTo) throws IOException { OutputStream to = new FileOutputStream(copyTo); copyStream(copyFrom, to); } /** * Copy an input stream to an output stream * * @param copyFrom * @param copyTo * @throws IOException */ public static void copyStream(InputStream copyFrom, OutputStream copyTo) throws IOException { byte[] buffer = new byte[1024]; int length; while ((length = copyFrom.read(buffer)) > 0) { copyTo.write(buffer, 0, length); } copyTo.flush(); copyTo.close(); copyFrom.close(); } }