Java InputStream to File writeStreamToFile(InputStream stream, File file)

Here you can find the source of writeStreamToFile(InputStream stream, File file)

Description

write Stream To File

License

LGPL

Declaration

public static void writeStreamToFile(InputStream stream, File file) 

Method Source Code

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

import java.io.File;

import java.io.FileNotFoundException;
import java.io.FileOutputStream;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

public class Main {
    public static void writeStreamToFile(InputStream stream, File file) {
        try {/*from  w  w  w.jav  a 2  s .  com*/
            OutputStream out = new FileOutputStream(file);

            byte[] buffer = new byte[1024];
            int read;
            while ((read = stream.read(buffer)) > 0) {
                out.write(buffer, 0, read);
            }
            out.close();
            stream.close();

        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}

Related

  1. writeStreamToFile(InputStream is, File out)
  2. writeStreamToFile(InputStream is, File toFile)
  3. writeStreamToFile(InputStream is, String fileName)
  4. writeStreamToFile(InputStream is, String path)
  5. writeStreamToFile(InputStream skypeFrameworkStream, File skypeFramework)
  6. writeStreamToFile(String chemin, String contenu)