Java FileOutputStream Write saveDownloadedFile(InputStream is, String destination)

Here you can find the source of saveDownloadedFile(InputStream is, String destination)

Description

Saves an input stream as file

License

Apache License

Parameter

Parameter Description
is Input stream
destination file path to be used

Exception

Parameter Description
IOException if there is an IO error

Declaration

public static void saveDownloadedFile(InputStream is, String destination) throws IOException 

Method Source Code


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

import com.google.common.io.ByteStreams;
import java.io.*;

public class Main {
    /**/*w w  w. j ava 2  s  .  co  m*/
     * Saves an input stream as file
     *
     * @param is          Input stream
     * @param destination file path to be used
     * @throws IOException if there is an IO error
     */
    public static void saveDownloadedFile(InputStream is, String destination) throws IOException {
        BufferedOutputStream out = null;
        try {
            out = new BufferedOutputStream(new FileOutputStream(new File(destination)));
            ByteStreams.copy(is, out);
        } finally {
            is.close();
            if (out != null) {
                out.close();
            }
        }
    }
}

Related

  1. saveCertReqToFile(String certReq, String fileLocation)
  2. saveColorTable(final float[][] table, final File file)
  3. saveContentToFile(DataHandler content, File outFile)
  4. saveData(byte[] data, String PATH, String fileName)
  5. saveDataToFile(String filePath, byte[] data)
  6. saveEntry(String destPath, ZipEntry target, ZipFile zf)
  7. saveFile(byte[] fileData, String outputDir, String fileName)
  8. saveFile(File f, InputStream stream)
  9. saveFile(File f, String fileName, File desDir)