Java InputStream Copy to File copyStream(InputStream in, File dest)

Here you can find the source of copyStream(InputStream in, File dest)

Description

copy Stream

License

Open Source License

Declaration

public static void copyStream(InputStream in, File dest) throws IOException 

Method Source Code


//package com.java2s;
/*//from   www . j  a va  2s  .c om
 * Copyright (c) 2011, Marc R?ttig.
 *
 * This file is part of GenericKnimeNodes.
 * 
 * GenericKnimeNodes is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation, either version 3 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 Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

import java.io.BufferedInputStream;

import java.io.File;

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

public class Main {
    public static void copyStream(InputStream in, File dest) throws IOException {
        FileOutputStream out = new FileOutputStream(dest);
        BufferedInputStream bin = new BufferedInputStream(in);
        byte[] buffer = new byte[2048];
        int len;
        while ((len = bin.read(buffer, 0, 2048)) != -1) {
            out.write(buffer, 0, len);
        }
        out.close();
        bin.close();
    }
}

Related

  1. copyStream(final InputStream in, final File dest)
  2. copyStream(final InputStream is, final File destinationFile)
  3. copyStream(InputStream copyFrom, File copyTo)
  4. copyStream(InputStream in, File dest)
  5. copyStreamIntoFile(File outFile, InputStream is)
  6. copyStreamsToFile(String path, Map streamMap)
  7. copyStreamsToFolder(Iterator> streams, File folder)