Here you can find the source of copyFile(String srcFileName, String dstFileName)
public static synchronized void copyFile(String srcFileName, String dstFileName) throws IOException
//package com.java2s; /***************************************************************************** * The contents of this file are subject to the Ricoh Source Code Public * License Version 1.0 (the "License"); you may not use this file except in * compliance with the License. You may obtain a copy of the License at * http://www.risource.org/RPL/*from w ww . j a v a2s. com*/ * * Software distributed under the License is distributed on an "AS IS" basis, * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License * for the specific language governing rights and limitations under the * License. * * This code was initially developed by Ricoh Innovations, Inc. Portions * created by Ricoh Innovations, Inc. are Copyright (C) 1995-1999. All * Rights Reserved. * * Contributor(s): * ***************************************************************************** */ import java.io.*; public class Main { /** * Copy a file. */ public static synchronized void copyFile(String srcFileName, String dstFileName) throws IOException { copyFile(new File(srcFileName), new File(dstFileName)); } public static synchronized void copyFile(File src, File dst) throws IOException { System.err.println("Substituting " + src.getPath() + "->" + dst.getPath()); FileWriter destination = null; FileReader source = null; try { source = new FileReader(src); destination = new FileWriter(dst); for (int i = source.read(); i != -1; i = source.read()) { destination.write((char) i); } destination.flush(); } catch (IOException e1) { // either from open or write. throw e1; } finally { if (source != null) source.close(); if (destination != null) destination.close(); } } }