Here you can find the source of saveToFile(String filePath, InputStream in)
private static void saveToFile(String filePath, InputStream in)
//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 { private static void saveToFile(String filePath, InputStream in) { FileOutputStream fos = null; BufferedInputStream bis = null; try {//from ww w. j av a2s .c o m int BUFFER_SIZE = 1024; byte[] buf = new byte[BUFFER_SIZE]; int size = 0; bis = new BufferedInputStream(in); fos = new FileOutputStream(filePath); while ((size = bis.read(buf)) != -1) fos.write(buf, 0, size); } catch (IOException e) { e.printStackTrace(); } finally { try { fos.close(); bis.close(); } catch (IOException e) { e.printStackTrace(); } } } }