Here you can find the source of copyFileUsingStream(InputStream sourceStream, File dest)
Parameter | Description |
---|---|
sourceStream | source file as an InputStream |
dest | destination given as a File |
Parameter | Description |
---|---|
IOException | an exception |
public static void copyFileUsingStream(InputStream sourceStream, File dest) throws IOException
//package com.java2s; /*/*from w w w.ja v a 2 s . co m*/ * This file is part of easyFPGA. * Copyright 2013-2015 os-cillation GmbH * * easyFPGA 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 3 of the License, or * (at your option) any later version. * * easyFPGA 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 easyFPGA. If not, see <http://www.gnu.org/licenses/>. * */ import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; public class Main { /** * Copy file from a given InputStream to a destination file * * @param sourceStream source file as an InputStream * @param dest destination given as a File * @throws IOException */ public static void copyFileUsingStream(InputStream sourceStream, File dest) throws IOException { if (sourceStream == null) { throw new IllegalArgumentException("Source stream is null"); } OutputStream destStream = null; try { destStream = new FileOutputStream(dest); byte[] buffer = new byte[1024]; int length; while ((length = sourceStream.read(buffer)) > 0) { destStream.write(buffer, 0, length); } } finally { sourceStream.close(); destStream.close(); } } }