Java InputStream to File inputStreamToFile(InputStream is)

Here you can find the source of inputStreamToFile(InputStream is)

Description

input Stream To File

License

Open Source License

Declaration

public static File inputStreamToFile(InputStream is) throws IOException 

Method Source Code


//package com.java2s;
//License from project: Open Source 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 File inputStreamToFile(InputStream is) throws IOException {
        File contentFile = File.createTempFile("tmpCont", ".txt");

        OutputStream outputStream = null;
        outputStream = new FileOutputStream(contentFile);

        int read = 0;
        byte[] bytes = new byte[1024];

        while ((read = is.read(bytes)) != -1) {
            outputStream.write(bytes, 0, read);
        }//from w ww.j  av  a 2  s .com

        outputStream.close();

        return contentFile;

    }
}

Related

  1. InputStreamToFile(final InputStream stream, final File file)
  2. inputStreamToFile(InputStream byteStream, String pathFileName)
  3. inputStreamToFile(InputStream in, File file)
  4. inputStreamToFile(InputStream ins, File file)
  5. inputstreamtofile(InputStream ins, File file)
  6. inputStreamToFile(InputStream is, File targetFile)
  7. inputStreamToFile(InputStream stream, File file)
  8. writeStreamToFile(File target, InputStream in)
  9. writeStreamToFile(InputStream _actual, File _file)