Here you can find the source of saveFile(final InputStream in, final String path, final String fileName)
public static void saveFile(final InputStream in, final String path, final String fileName) 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 { public static void saveFile(final InputStream in, final String path, final String fileName) throws IOException { OutputStream os = null;// w ww . j ava 2 s. c o m try { File distDir = new File(path); if (!distDir.exists()) { distDir.mkdirs(); } os = new FileOutputStream(new File(distDir, fileName)); byte[] buffer = new byte[256]; int len = in.read(buffer); while (len != -1) { os.write(buffer, 0, len); len = in.read(buffer); } } catch (IOException e) { throw new IOException(); } finally { if (null != os) os.close(); if (null != in) in.close(); } } }