Java InputStream Copy to File copyStreamToFile(InputStream in, File target)

Here you can find the source of copyStreamToFile(InputStream in, File target)

Description

Copy the contents of the given inputstream to given targetfile.

License

Open Source License

Declaration

public static boolean copyStreamToFile(InputStream in, File target) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.io.File;
import java.io.FileOutputStream;

import java.io.InputStream;
import java.io.OutputStream;

public class Main {
    /** Copy the contents of the given inputstream to given targetfile.
     * The inputstream in closed after copy.
     *//*from ww  w.  j av a  2  s  . c om*/
    public static boolean copyStreamToFile(InputStream in, File target) {
        try {
            OutputStream out = new FileOutputStream(target);
            byte[] buf = new byte[16384];
            int c;

            while ((c = in.read(buf)) != -1)
                out.write(buf, 0, c);

            in.close();
            return true;
        } catch (Exception e) {
            System.out.println("copyStreamToFile:" + e);
            return false;
        }
    }
}

Related

  1. copyStreamsToFolder(Iterator> streams, File folder)
  2. copyStreamToFile(final File to, final InputStream from)
  3. copyStreamToFile(InputStream from, File to)
  4. copyStreamToFile(InputStream in, File destination)
  5. copyStreamToFile(InputStream in, File out)
  6. copyStreamToFile(InputStream inputStream, File destFile)
  7. copyStreamToFile(InputStream pInputStream, File pFile)
  8. copyStreamToFile(InputStream source, File target)
  9. copyStreamToFile(InputStream stream, File destFile)