public static void copyFile(InputStream input, File destination) throws IOException { OutputStream output = null; try { output = new FileOutputStream(destination); byte[] buffer = new byte[1024]; int bytesRead = input.read(buffer); while (bytesRead >= 0) { output.write(buffer, 0, bytesRead); bytesRead = input.read(buffer); } } finally { if (input != null) close(input); if (output != null) close(output); } }