Here you can find the source of writeStreamToFile(InputStream is, File file)
protected static void writeStreamToFile(InputStream is, File file)
//package com.java2s; /******************************************************************************* * Copyright 2012 Geoscience Australia/*from w w w .jav a 2s.c o m*/ * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. ******************************************************************************/ import java.io.BufferedOutputStream; import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; public class Main { protected static void writeStreamToFile(InputStream is, File file) { byte[] buffer = new byte[512]; BufferedOutputStream out = null; try { try { out = new BufferedOutputStream(new FileOutputStream(file)); while (true) { int read = is.read(buffer); if (read < 0) { break; } out.write(buffer, 0, read); } } finally { if (out != null) { out.close(); } } } catch (IOException e) { } } }