Java InputStream to File writeStreamToFile(InputStream is, String path)

Here you can find the source of writeStreamToFile(InputStream is, String path)

Description

Reads an input stream and writes its content to a file

License

LGPL

Parameter

Parameter Description
is a parameter
path a parameter

Exception

Parameter Description
IOException an exception

Declaration

public static File writeStreamToFile(InputStream is, String path) throws IOException 

Method Source Code


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

import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;

public class Main {
    /**/*from   w  w w.j a  v a2s  .c o m*/
     * Reads an input stream and writes its content to a file
     * 
     * @param is
     * @param path
     * @return
     * @throws IOException
     */
    public static File writeStreamToFile(InputStream is, String path) throws IOException {
        File file = new File(path);
        BufferedInputStream bis = new BufferedInputStream(is);
        BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(file));
        int inByte;

        while ((inByte = bis.read()) != -1) {
            bos.write(inByte);
        }
        bis.close();
        bos.close();
        return file;
    }
}

Related

  1. writeStreamToFile(InputStream inputStream, String extension)
  2. writeStreamToFile(InputStream is, File file)
  3. writeStreamToFile(InputStream is, File out)
  4. writeStreamToFile(InputStream is, File toFile)
  5. writeStreamToFile(InputStream is, String fileName)
  6. writeStreamToFile(InputStream skypeFrameworkStream, File skypeFramework)
  7. writeStreamToFile(InputStream stream, File file)
  8. writeStreamToFile(String chemin, String contenu)