Here you can find the source of inputStreamToFile(InputStream byteStream, String pathFileName)
public static void inputStreamToFile(InputStream byteStream, String pathFileName)
//package com.java2s; //License from project: Apache License import java.io.FileOutputStream; import java.io.InputStream; public class Main { public static void inputStreamToFile(InputStream byteStream, String pathFileName) { InputStream bStream = null; FileOutputStream fileOutStream = null; try {//w w w . ja v a 2 s .c om bStream = byteStream; fileOutStream = new FileOutputStream(pathFileName); byte[] buffer = new byte[10]; int nbytes = 0; // Number of bytes read // file output stream while ((nbytes = bStream.read(buffer)) != -1) { // Read from fileOutStream.write(buffer, 0, nbytes); // Write to file stream } } catch (Exception e) { e.printStackTrace(); } finally { try { bStream.close(); } catch (Exception e) { } try { fileOutStream.close(); } catch (Exception e) { } } } }