Here you can find the source of copyFile(final File source, final File dest)
Parameter | Description |
---|---|
source | Fichero origen con el contenido que queremos copiar. |
dest | Fichero destino de los datos. |
Parameter | Description |
---|---|
IOException | SI ocurre algun problema durante la copia |
public static void copyFile(final File source, final File dest) throws IOException
//package com.java2s; /* Copyright (C) 2011 [Gobierno de Espana] * This file is part of "Cliente @Firma". * "Cliente @Firma" 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. * - or The European Software License; either version 1.1 or (at your option) any later version. * Date: 11/01/11/*from w ww .j a v a2s . c o m*/ * You may contact the copyright holder at: soporte.afirma5@mpt.es */ import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; import java.nio.MappedByteBuffer; import java.nio.channels.FileChannel; public class Main { /** Copia un fichero. * @param source Fichero origen con el contenido que queremos copiar. * @param dest Fichero destino de los datos. * @throws IOException SI ocurre algun problema durante la copia */ public static void copyFile(final File source, final File dest) throws IOException { if (source == null || dest == null) { throw new IllegalArgumentException( "Ni origen ni destino de la copia pueden ser nulos"); //$NON-NLS-1$ } final FileInputStream is = new FileInputStream(source); final FileOutputStream os = new FileOutputStream(dest); final FileChannel in = is.getChannel(); final FileChannel out = os.getChannel(); final MappedByteBuffer buf = in.map(FileChannel.MapMode.READ_ONLY, 0, in.size()); out.write(buf); in.close(); out.close(); is.close(); os.close(); } }