Java FileOutputStream Write saveInputStream(InputStream _input_stream, File _file)

Here you can find the source of saveInputStream(InputStream _input_stream, File _file)

Description

Save an Object to a given filename.

License

Mozilla Public License

Parameter

Parameter Description
_input_stream The InputStream to be saved.
_file The target file.

Return

A String containing the name of the file.

Declaration

public static String saveInputStream(InputStream _input_stream, File _file) throws IOException 

Method Source Code


//package com.java2s;
//License from project: Mozilla Public License 

import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;

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

import java.io.IOException;

public class Main {
    /**/*  w w  w.  j  a v  a2  s .  c  o m*/
     * Save an {@link Object} to a given filename.
     * @param _input_stream The InputStream to be saved.
     * @param _file The target file.
     * @return A String containing the name of the file.
     */
    public static String saveInputStream(InputStream _input_stream, File _file) throws IOException {
        BufferedInputStream input_stream = new BufferedInputStream(_input_stream);
        BufferedOutputStream output_stream = new BufferedOutputStream(new FileOutputStream(_file));

        int stream_byte;
        while ((stream_byte = input_stream.read()) != -1)
            output_stream.write(stream_byte);

        output_stream.flush();
        input_stream.close();

        return _file.getAbsolutePath();
    }
}

Related

  1. saveFile(String text, File saveFile)
  2. saveFileBinary(final File file, final byte[] data)
  3. SaveFileFromInputStream(InputStream in, String fileName, String path)
  4. SaveFileFromInputStream(InputStream stream, String path, String filename)
  5. saveInFile(String filename, String content, String charsetName)
  6. saveInputStream(InputStream is, String filePath)
  7. saveInt16bit(String filename, int[] intData)
  8. saveIntArrayToFile(int[] array, File file)
  9. saveKeyToFile(String key)