Java FileOutputStream Write saveStreamToFile(InputStream in, File outFile)

Here you can find the source of saveStreamToFile(InputStream in, File outFile)

Description

save Stream To File

License

Apache License

Declaration

public static void saveStreamToFile(InputStream in, File outFile) 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 saveStreamToFile(InputStream in, File outFile) throws IOException {
        FileOutputStream out = null;
        try {//from  w  w  w. ja v a 2s .c  o m
            out = new FileOutputStream(outFile);
            byte[] buf = new byte[4096];
            int bytes_read;
            while ((bytes_read = in.read(buf)) != -1)
                out.write(buf, 0, bytes_read);
        } finally {
            if (in != null)
                try {
                    in.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }

            if (out != null)
                try {
                    out.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
        }
    }
}

Related

  1. saveLongList(String file, Collection c, boolean append)
  2. saveProxyClass(String path, String proxyClassName, Class[] interfaces)
  3. saveResouce(String resourceName, String outputFile)
  4. saveStream(InputStream is, File output)
  5. saveStream(InputStream stream, File targetFile)
  6. saveStreamToFile(InputStream is, File destFile)
  7. saveStringIntoFile(File file, String contents)
  8. saveStringIntoFile(String filePath, String contents)
  9. saveStringsList(String file, Collection c)