Java InputStream to File writeStreamToFile(InputStream is, File out)

Here you can find the source of writeStreamToFile(InputStream is, File out)

Description

Writes a given InputStream to a file.

License

Open Source License

Parameter

Parameter Description
is a parameter
out a parameter

Declaration

@SuppressWarnings("unused")
public static void writeStreamToFile(InputStream is, File out) 

Method Source Code

//package com.java2s;
/**//from   w  ww  . ja va  2 s .c  o  m
    
   BlackBoard BreadBoard Designer
   Written and maintained by Matthias Pueski 
       
   Copyright (c) 2010-2011 Matthias Pueski
       
   This program is free software; you can redistribute it and/or
   modify it under the terms of the GNU General Public License
   as published by the Free Software Foundation; either version 2
   of the License, or (at your option) any later version.
       
   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.
       
   You should have received a copy of the GNU General Public License
   along with this program; if not, write to the Free Software
   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
    
*/

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

public class Main {
    /**
     * Writes a given <code>InputStream</code> to a file.
     * 
     * @param is
     * @param out
     */
    @SuppressWarnings("unused")
    public static void writeStreamToFile(InputStream is, File out) {

        byte[] b;

        try {

            FileOutputStream fos = new FileOutputStream(out);

            b = new byte[is.available()];

            for (int n; (n = is.read(b)) != -1;) {
                fos.write(b);
            }

            fos.close();

        } catch (IOException e) {
            e.printStackTrace();
        }

    }
}

Related

  1. writeStreamToFile(InputStream in, String fileName)
  2. writeStreamToFile(InputStream inputStream, File file)
  3. writeStreamToFile(InputStream inputStream, File targetFile)
  4. writeStreamToFile(InputStream inputStream, String extension)
  5. writeStreamToFile(InputStream is, File file)
  6. writeStreamToFile(InputStream is, File toFile)
  7. writeStreamToFile(InputStream is, String fileName)
  8. writeStreamToFile(InputStream is, String path)
  9. writeStreamToFile(InputStream skypeFrameworkStream, File skypeFramework)