Here you can find the source of inputStreamToFile(InputStream is)
public static File inputStreamToFile(InputStream is) throws IOException
//package com.java2s; //License from project: Open Source License import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; public class Main { public static File inputStreamToFile(InputStream is) throws IOException { File contentFile = File.createTempFile("tmpCont", ".txt"); OutputStream outputStream = null; outputStream = new FileOutputStream(contentFile); int read = 0; byte[] bytes = new byte[1024]; while ((read = is.read(bytes)) != -1) { outputStream.write(bytes, 0, read); }//from w ww.j av a 2 s .com outputStream.close(); return contentFile; } }