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

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

Description

input Stream File

License

Apache License

Declaration

public static void inputStream2File(InputStream in, File file) 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;

import java.io.OutputStream;

public class Main {
    public static void inputStream2File(InputStream in, File file) throws IOException {
        OutputStream os = new FileOutputStream(file);

        int bytesRead = 0;
        byte[] buffer = new byte[8192];
        try {/*from   www .  j a v  a2 s .  c o m*/
            while ((bytesRead = in.read(buffer, 0, 8192)) != -1) {
                os.write(buffer, 0, bytesRead);
            }
        } finally {
            try {
                os.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
            try {
                in.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}

Related

  1. InputStream2File(InputStream in, String filePath)
  2. InputStreamToFile(final InputStream stream, final File file)
  3. inputStreamToFile(InputStream byteStream, String pathFileName)
  4. inputStreamToFile(InputStream in, File file)