Here you can find the source of copyFile(FileChannel in, FileChannel out)
Parameter | Description |
---|---|
in | the input file channel |
out | the output file channel |
size | the size of the file |
Parameter | Description |
---|---|
IOException | if there is an error reading or writing |
public static void copyFile(FileChannel in, FileChannel out) throws IOException
//package com.java2s; /**/*from ww w .j av a2 s.c o m*/ * Project Wonderland * * Copyright (c) 2004-2009, Sun Microsystems, Inc., All Rights Reserved * * Redistributions in source code form must reproduce the above * copyright and this condition. * * The contents of this file are subject to the GNU General Public * License, Version 2 (the "License"); you may not use this file * except in compliance with the License. A copy of the License is * available at http://www.opensource.org/licenses/gpl-license.php. * * Sun designates this particular file as subject to the "Classpath" * exception as provided by Sun in the License file that accompanied * this code. */ import java.io.IOException; import java.nio.channels.FileChannel; public class Main { /** * Optimized copy from one file to another * @param in the input file channel * @param out the output file channel * @param size the size of the file * @throws IOException if there is an error reading or writing */ public static void copyFile(FileChannel in, FileChannel out) throws IOException { long position = 0; long read; while ((read = in.transferTo(position, 16 * 1024, out)) > 0) { position += read; } } }