Here you can find the source of writeStreamToFile(InputStream is, String fileName)
Parameter | Description |
---|---|
is | a parameter |
fileName | a parameter |
Parameter | Description |
---|---|
IOException | an exception |
public static final void writeStreamToFile(InputStream is, String fileName) 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 { private static final int BUFFER_LENGTH = 1024; /**/*w ww . j ava 2 s. c om*/ * Write a stream's content to a file. * @param is * @param fileName * @throws IOException */ public static final void writeStreamToFile(InputStream is, String fileName) throws IOException { //Make sure the dir path is ready File file = new File(fileName); file.getParentFile().mkdirs(); FileOutputStream fos = null; byte[] buf = new byte[BUFFER_LENGTH]; try { fos = new FileOutputStream(file); int len; while ((len = is.read(buf, 0, BUFFER_LENGTH)) > -1) { fos.write(buf, 0, len); } } finally { if (fos != null) { fos.close(); } } } }