Here you can find the source of saveStream(InputStream is, File output)
public static void saveStream(InputStream is, File output) throws IOException
//package com.java2s; /*//from w ww . j a v a 2s . c o m * Copyright (C) 2010-2015 JPEXS, All rights reserved. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 3.0 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library. */ import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; public class Main { public static void saveStream(InputStream is, File output) throws IOException { byte[] buf = new byte[1024]; int cnt; try (FileOutputStream fos = new FileOutputStream(output)) { while ((cnt = is.read(buf)) > 0) { fos.write(buf, 0, cnt); fos.flush(); } } } }