Java InputStream to File inputStreamToFile(InputStream in, File file)

Here you can find the source of inputStreamToFile(InputStream in, File file)

Description

input Stream To File

License

Apache License

Declaration

public static void inputStreamToFile(InputStream in, File file) throws Exception 

Method Source Code


//package com.java2s;
//License from project: Apache License 

import java.io.BufferedOutputStream;

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

import java.io.InputStream;

import java.util.logging.Logger;

public class Main {
    private static final Logger LOG = Logger.getLogger("Utils");

    public static void inputStreamToFile(InputStream in, File file) throws Exception {
        BufferedOutputStream out = null;

        byte[] b = new byte[8192];
        try {/*from  w ww  .  j  a  va  2s .com*/
            out = new BufferedOutputStream(new FileOutputStream(file));

            for (int n; (n = in.read(b)) != -1;) {
                out.write(b, 0, n);
            }
        } catch (Exception e) {
            LOG.severe(e.getMessage());
        } finally {
            if (out != null) {
                out.flush();
                out.close();
            }
            if (in != null) {
                in.close();
            }
        }
    }
}

Related

  1. inputStream2File(InputStream in, File file)
  2. InputStream2File(InputStream in, String filePath)
  3. InputStreamToFile(final InputStream stream, final File file)
  4. inputStreamToFile(InputStream byteStream, String pathFileName)
  5. inputStreamToFile(InputStream ins, File file)
  6. inputstreamtofile(InputStream ins, File file)
  7. inputStreamToFile(InputStream is)
  8. inputStreamToFile(InputStream is, File targetFile)