Here you can find the source of writeFile(File file, InputStream inStream)
public static int writeFile(File file, InputStream inStream) throws IOException
//package com.java2s; import java.io.*; public class Main { private final static int BUFFER = 8192; public static void writeFile(File file, byte[] data) throws Exception { DataOutputStream out = null; if (null != file && null != data) { try { out = new DataOutputStream(new FileOutputStream(file)); out.write(data);//w w w. j a v a 2 s. c o m } finally { if (out != null) { out.close(); } } } } public static int writeFile(File file, InputStream inStream) throws IOException { long dataSize = 0; DataInputStream in = null; DataOutputStream out = null; if (null != inStream && null != file) { try { byte buffer[] = new byte[BUFFER]; out = new DataOutputStream(new FileOutputStream(file)); in = new DataInputStream(inStream); int nbyteread; while ((nbyteread = in.read(buffer)) != -1) { out.write(buffer, 0, nbyteread); dataSize += nbyteread; } } finally { if (in != null) { in.close(); } if (out != null) { out.close(); } } } return (int) (dataSize / 1024); } }