Java InputStream Copy to File copyStreamToFile(InputStream from, File to)

Here you can find the source of copyStreamToFile(InputStream from, File to)

Description

copy Stream To File

License

Open Source License

Declaration

public static void copyStreamToFile(InputStream from, File to) throws IOException 

Method Source Code


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

import java.io.*;

public class Main {
    private static final byte[] BUFFER = new byte[64 * 1024];

    public static void copyStreamToFile(InputStream from, File to) throws IOException {
        to.getParentFile().mkdirs();//  ww  w  . j  av a 2  s .com
        OutputStream out = new BufferedOutputStream(new FileOutputStream(to));
        try {
            copyStream(from, out);
        } finally {
            out.close();
        }
    }

    public static void copyStream(InputStream in, OutputStream out) throws IOException {
        while (true) {
            int read = in.read(BUFFER);
            if (read < 0)
                break;
            out.write(BUFFER, 0, read);
        }
    }
}

Related

  1. copyStream(InputStream in, File dest)
  2. copyStreamIntoFile(File outFile, InputStream is)
  3. copyStreamsToFile(String path, Map streamMap)
  4. copyStreamsToFolder(Iterator> streams, File folder)
  5. copyStreamToFile(final File to, final InputStream from)
  6. copyStreamToFile(InputStream in, File destination)
  7. copyStreamToFile(InputStream in, File out)
  8. copyStreamToFile(InputStream in, File target)
  9. copyStreamToFile(InputStream inputStream, File destFile)