Here you can find the source of copyStreamToFile(InputStream input, String outputPath)
public static File copyStreamToFile(InputStream input, String outputPath)
//package com.java2s; //License from project: LGPL import java.io.BufferedOutputStream; import java.io.DataOutputStream; import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; public class Main { public static File copyStreamToFile(InputStream input, String outputPath) { File file = new File(outputPath); try {//from w w w. j av a2s.c om DataOutputStream out = new DataOutputStream( new BufferedOutputStream(new FileOutputStream(file))); // Transfer bytes from in to out InputStream is = input; byte[] buf = new byte[1024]; int len; while ((len = is.read(buf)) > 0) { out.write(buf, 0, len); } is.close(); out.close(); } catch (IOException e) { System.err.println("Error Writing/Reading Streams."); } return file; } }