Here you can find the source of toFile(InputStream inputStream)
public static File toFile(InputStream inputStream) throws IOException
//package com.java2s; //License from project: LGPL 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 toFile(InputStream inputStream) throws IOException { File result = null;/*from ww w . j a v a2s . c o m*/ OutputStream outputStream = null; try { result = File.createTempFile(".tmp", ".tmp"); // result = new File("/Users/mkyong/Downloads/holder-new.js"); // write the inputStream to a FileOutputStream outputStream = new FileOutputStream(result); int read = 0; byte[] bytes = new byte[1024]; while ((read = inputStream.read(bytes)) != -1) { outputStream.write(bytes, 0, read); } } finally { if (inputStream != null) { try { inputStream.close(); } catch (IOException e) { e.printStackTrace(); } } if (outputStream != null) { try { // outputStream.flush(); outputStream.close(); } catch (IOException e) { e.printStackTrace(); } } } return result; } }