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

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

Description

copy Stream To File

License

Apache License

Declaration

public static void copyStreamToFile(InputStream in, File out) throws IOException 

Method Source Code


//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 void copyStreamToFile(InputStream in, File out) throws IOException {
        FileOutputStream fos = null;
        try {/*from   w w  w.j  a  v a  2s  . co  m*/
            fos = new FileOutputStream(out);
            byte[] buf = new byte[1024];
            int i = 0;
            while ((i = in.read(buf)) != -1) {
                fos.write(buf, 0, i);
            }
        } finally {
            if (in != null) {
                try {
                    in.close();
                } catch (IOException e) {
                }
            }
            if (fos != null) {
                try {
                    fos.close();
                } catch (IOException e) {
                }
            }
        }
    }
}

Related

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