Here you can find the source of writeFile(InputStream is, File file)
private static void writeFile(InputStream is, File file) throws IOException
//package com.java2s; //License from project: Open Source License import java.io.*; public class Main { private static void writeFile(InputStream is, File file) throws IOException { file.getParentFile().mkdirs();/*www . j av a 2 s .co m*/ try (FileOutputStream fos = new FileOutputStream(file)) { final byte data[] = new byte[1024]; int count; while ((count = is.read(data, 0, 1024)) != -1) { fos.write(data, 0, count); } } } }