Java FileOutputStream Write saveFile(File f, InputStream stream)

Here you can find the source of saveFile(File f, InputStream stream)

Description

saveFile Saves a given input stream to a specified file

License

Apache License

Parameter

Parameter Description
f a parameter
stream a parameter

Exception

Parameter Description
Exception an exception

Declaration

public static void saveFile(File f, InputStream stream) throws Exception 

Method Source Code


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

import java.io.File;

import java.io.FileOutputStream;

import java.io.InputStream;
import java.io.OutputStream;

public class Main {
    /**/* w w  w .  j  a va  2s . c om*/
     * saveFile
     * Saves a given input stream to a specified file
     * @param f
     * @param stream
     * @throws Exception
     */
    public static void saveFile(File f, InputStream stream) throws Exception {
        OutputStream out = new FileOutputStream(f);

        int read = 0;
        byte[] bytes = new byte[1024];
        while ((read = stream.read(bytes)) != -1) {
            out.write(bytes, 0, read);
        }
        stream.close();
        out.flush();
        out.close();

    }
}

Related

  1. saveData(byte[] data, String PATH, String fileName)
  2. saveDataToFile(String filePath, byte[] data)
  3. saveDownloadedFile(InputStream is, String destination)
  4. saveEntry(String destPath, ZipEntry target, ZipFile zf)
  5. saveFile(byte[] fileData, String outputDir, String fileName)
  6. saveFile(File f, String fileName, File desDir)
  7. saveFile(File f, String fileName, File desDir)
  8. saveFile(File file, byte[] contenido)
  9. saveFile(File file, InputStream is)