Java tutorial
//package com.java2s; //License from project: Apache License import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; public class Main { public static boolean copyFile(InputStream inputStream, File target) { boolean result = false; if (target == null) { return result; } FileOutputStream fileOutputStream = null; try { fileOutputStream = new FileOutputStream(target); byte[] buffer = new byte[1024]; while (inputStream.read(buffer) > 0) { fileOutputStream.write(buffer); } result = true; } catch (IOException e) { e.printStackTrace(); } finally { if (fileOutputStream != null) { try { fileOutputStream.flush(); fileOutputStream.close(); } catch (IOException e) { } } } return result; } }