Here you can find the source of saveTo(InputStream in, String fileName)
public static void saveTo(InputStream in, String fileName) throws IOException
//package com.java2s; //License from project: Open Source License import java.io.*; public class Main { public static void saveTo(InputStream in, String fileName) throws IOException { saveTo(in, new File(fileName)); }//w ww . j av a 2 s.co m public static void saveTo(InputStream in, File file) throws IOException { try (OutputStream out = new FileOutputStream(file)) { byte[] buffer = new byte[4096]; while (true) { int read = in.read(buffer, 0, 4096); if (read <= 0) { out.flush(); in.close(); out.close(); break; } out.write(buffer, 0, read); } } } }