Java FileOutputStream Create writeFile(InputStream in, File file)

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

Description

Saves an Input Stream to a file.

License

Apache License

Parameter

Parameter Description
in The Input Stream.
file File to save.

Exception

Parameter Description
IOException an exception

Declaration

public static void writeFile(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;

public class Main {
    /**/*from   ww w  .  j av a  2 s.c o m*/
     * Saves an Input Stream to a file.
     * 
     * @param in   The Input Stream.
     * @param file   File to save.
     * @throws IOException
     */
    public static void writeFile(InputStream in, File file) throws IOException {
        FileOutputStream out = new FileOutputStream(file);

        byte[] buffer = new byte[1024];
        int len = in.read(buffer);
        while (len != -1) {
            out.write(buffer, 0, len);
            len = in.read(buffer);
        }

        out.close();
        in.close();

    }
}

Related

  1. getOutputStreamForFile(String filename)
  2. writeFile(File outFile, ZipInputStream zipInputStream, ZipEntry entry)
  3. writeFile(FileOutputStream fileoutputstream, byte abyte0[], int i)
  4. writeFile(final String filename, final byte[] data)
  5. writeFile(final String fileNamePath, final byte[] daten)
  6. writeFile(InputStream inputFile, String path, String fullFileName)
  7. writeFile(InputStream inputStream, String filename, long lastModified)
  8. writeFile(InputStream is, File file)
  9. writeFile(InputStream is, File outFile)