Here you can find the source of writeStreamToFile(InputStream inputStream, String extension)
public static File writeStreamToFile(InputStream inputStream, String extension) 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.util.UUID; public class Main { public static File writeStreamToFile(InputStream inputStream, String extension) throws IOException { File file = File.createTempFile("file" + UUID.randomUUID(), "." + extension); return writeStreamToFile(inputStream, extension, file); }/*from w w w . jav a2 s . com*/ public static File writeStreamToFile(InputStream inputStream, String extension, File file) throws IOException { FileOutputStream output = new FileOutputStream(file); byte buf[] = new byte[1024]; int len; while ((len = inputStream.read(buf)) > 0) { output.write(buf, 0, len); } output.close(); inputStream.close(); return file; } }