Java InputStream to File inputStreamToFile(InputStream byteStream, String pathFileName)

Here you can find the source of inputStreamToFile(InputStream byteStream, String pathFileName)

Description

input Stream To File

License

Apache License

Declaration

public static void inputStreamToFile(InputStream byteStream, String pathFileName) 

Method Source Code


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

import java.io.FileOutputStream;
import java.io.InputStream;

public class Main {
    public static void inputStreamToFile(InputStream byteStream, String pathFileName) {

        InputStream bStream = null;
        FileOutputStream fileOutStream = null;
        try {//w w w  .  ja v a 2  s .c  om

            bStream = byteStream;

            fileOutStream = new FileOutputStream(pathFileName);

            byte[] buffer = new byte[10];
            int nbytes = 0; // Number of bytes read

            // file output stream
            while ((nbytes = bStream.read(buffer)) != -1) { // Read from

                fileOutStream.write(buffer, 0, nbytes); // Write to file stream
            }

        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            try {
                bStream.close();
            } catch (Exception e) {
            }
            try {
                fileOutStream.close();
            } catch (Exception e) {
            }

        }

    }
}

Related

  1. inputStream2File(InputStream in, File file)
  2. InputStream2File(InputStream in, String filePath)
  3. InputStreamToFile(final InputStream stream, final File file)
  4. inputStreamToFile(InputStream in, File file)
  5. inputStreamToFile(InputStream ins, File file)
  6. inputstreamtofile(InputStream ins, File file)
  7. inputStreamToFile(InputStream is)