Here you can find the source of writeFile(InputStream inputStream, OutputStream outputStream)
private static void writeFile(InputStream inputStream, OutputStream outputStream) throws IOException
//package com.java2s; import java.io.Closeable; import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.io.OutputStreamWriter; public class Main { public static void writeFile(String filepath, String text) { OutputStreamWriter wr = null; try {/*from w w w .ja va 2s. co m*/ File file = new File(filepath); if (!file.exists()) { file.getParentFile().mkdirs(); } wr = new OutputStreamWriter(new FileOutputStream(filepath, false), "UTF8"); wr.write(text); wr.flush(); } catch (Exception e) { e.printStackTrace(); } finally { if (wr != null) { try { wr.close(); } catch (IOException e) { e.printStackTrace(); } } } } private static void writeFile(InputStream inputStream, OutputStream outputStream) throws IOException { final byte[] buf = new byte[10240]; int len; while ((len = inputStream.read(buf)) != -1) { outputStream.write(buf, 0, len); } outputStream.flush(); closeIOStream(outputStream); closeIOStream(inputStream); } public static void closeIOStream(Closeable stream) { if (stream != null) { try { stream.close(); } catch (IOException e) { e.printStackTrace(); } } } }