Here you can find the source of saveToFile(InputStream in, String fileName)
public static void saveToFile(InputStream in, String fileName) throws IOException
//package com.java2s; //License from project: Apache License import java.io.BufferedInputStream; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; public class Main { public static void saveToFile(InputStream in, String fileName) throws IOException { FileOutputStream fos = null; BufferedInputStream bis = null; int BUFFER_SIZE = 1024; byte[] buf = new byte[BUFFER_SIZE]; int size = 0; bis = new BufferedInputStream(in); fos = new FileOutputStream(fileName); while ((size = bis.read(buf)) != -1) fos.write(buf, 0, size);//from ww w . j ava 2 s. co m fos.close(); bis.close(); } }