Here you can find the source of copyFile(InputStream in, File to)
Parameter | Description |
---|---|
in | a parameter |
to | a parameter |
Parameter | Description |
---|---|
IOException | an exception |
public static void copyFile(InputStream in, File to) throws IOException
//package com.java2s; /*/*from ww w . java 2 s . co m*/ * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). * All rights reserved. * This component and the accompanying materials are made available * under the terms of the License "Eclipse Public License v1.0" * which accompanies this distribution, and is available * at the URL "http://www.eclipse.org/legal/epl-v10.html". * * Initial Contributors: * Nokia Corporation - initial contribution. * * Contributors: * * Description: * */ import java.io.*; public class Main { /** * Copy from an input stream to a file * * @param in * @param to * @throws IOException */ public static void copyFile(InputStream in, File to) throws IOException { FileOutputStream out = new FileOutputStream(to); int len; byte[] buffer = new byte[4096]; while ((len = in.read(buffer)) != -1) { out.write(buffer, 0, len); } out.close(); in.close(); } /** Copy a single file from 'from' to 'to' * * @param from * @param to * @throws IOException */ public static void copyFile(File from, File to) throws IOException { FileInputStream in = new FileInputStream(from); copyFile(in, to); } }