Java tutorial
//package com.java2s; import java.io.File; import java.io.DataInputStream; import java.io.InputStream; import java.io.FileOutputStream; public class Main { public static File WriteStreamToFile(InputStream resStream) { try { byte[] bytes = new byte[resStream.available()]; File tmpFile = File.createTempFile("z4-", ".tmp"); tmpFile.deleteOnExit(); DataInputStream dis = new DataInputStream(resStream); dis.readFully(bytes); FileOutputStream foutStream = new FileOutputStream(tmpFile.getPath()); foutStream.write(bytes); foutStream.close(); dis.close(); return tmpFile; } catch (Exception e) { e.printStackTrace(); } return null; } }