Java InputStream to File writeStreamToFile(InputStream inputStream, File file)

Here you can find the source of writeStreamToFile(InputStream inputStream, File file)

Description

write Stream To File

License

Open Source License

Declaration

public static void writeStreamToFile(InputStream inputStream, File file)
             throws IOException 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2014 Gabriel Skantze.//from  w  ww .j a va2s.  c om
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the GNU Public License v3.0
 * which accompanies this distribution, and is available at
 * http://www.gnu.org/licenses/gpl.html
 * 
 * Contributors:
 *     Gabriel Skantze - initial API and implementation
 ******************************************************************************/

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 void writeStreamToFile(InputStream inputStream, File file)
            throws IOException {
        FileOutputStream fout = new FileOutputStream(file);
        copyStream(inputStream, fout);
        fout.close();
    }

    public static void copyStream(InputStream is, OutputStream os)
            throws IOException {
        byte[] b = new byte[256];
        int r = 0;
        while ((r = is.read(b, 0, b.length)) > 0) {
            os.write(b, 0, r);
        }
    }
}

Related

  1. inputStreamToFile(InputStream stream, File file)
  2. writeStreamToFile(File target, InputStream in)
  3. writeStreamToFile(InputStream _actual, File _file)
  4. writeStreamToFile(InputStream in, OutputStream out)
  5. writeStreamToFile(InputStream in, String fileName)
  6. writeStreamToFile(InputStream inputStream, File targetFile)
  7. writeStreamToFile(InputStream inputStream, String extension)
  8. writeStreamToFile(InputStream is, File file)
  9. writeStreamToFile(InputStream is, File out)