Here you can find the source of copy(String srcFileName, String destFileName)
This may be a resource leak: http://bugs.sun.com/view_bug.do?bug_id=4724038 We may have to reconsider using nio for this, or apply one of the horrible workarounds listed in the bug report above.
public static void copy(String srcFileName, String destFileName) throws IOException
//package com.java2s; /******************************************************************************* * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors:/* w w w . j av a 2 s . c o m*/ * IBM Corporation - initial API and implementation *******************************************************************************/ import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; import java.nio.MappedByteBuffer; import java.nio.channels.FileChannel; public class Main { /** * This may be a resource leak: * http://bugs.sun.com/view_bug.do?bug_id=4724038 * * We may have to reconsider using nio for this, or apply one of the horrible * workarounds listed in the bug report above. */ public static void copy(String srcFileName, String destFileName) throws IOException { if (srcFileName == null) { throw new IllegalArgumentException("srcFileName is null"); } if (destFileName == null) { throw new IllegalArgumentException("destFileName is null"); } FileChannel src = null; FileChannel dest = null; try { src = new FileInputStream(srcFileName).getChannel(); dest = new FileOutputStream(destFileName).getChannel(); long n = src.size(); MappedByteBuffer buf = src.map(FileChannel.MapMode.READ_ONLY, 0, n); dest.write(buf); } finally { if (dest != null) { try { dest.close(); } catch (IOException e1) { } } if (src != null) { try { src.close(); } catch (IOException e1) { } } } } }