Java InputStream to File inputstreamtofile(InputStream ins, File file)

Here you can find the source of inputstreamtofile(InputStream ins, File file)

Description

inputstreamtofile

License

Apache License

Declaration

public static void inputstreamtofile(InputStream ins, File file) 

Method Source Code

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

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 inputstreamtofile(InputStream ins, File file) {
        OutputStream os = null;/*from   w w  w.jav a 2 s.  c  o  m*/
        try {
            os = new FileOutputStream(file);
        } catch (FileNotFoundException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        int bytesRead = 0;
        byte[] buffer = new byte[8192];
        try {
            while ((bytesRead = ins.read(buffer, 0, 8192)) != -1) {
                os.write(buffer, 0, bytesRead);
            }
            os.close();
            ins.close();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            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)
  5. inputStreamToFile(InputStream ins, File file)
  6. inputStreamToFile(InputStream is)
  7. inputStreamToFile(InputStream is, File targetFile)
  8. inputStreamToFile(InputStream stream, File file)
  9. writeStreamToFile(File target, InputStream in)