Here you can find the source of copyFile(String fileIn, String fileOut)
public static void copyFile(String fileIn, String fileOut) throws IOException
//package com.java2s; /*/* www. java 2 s.c o m*/ * Copyright (C) 2009, Edmundo Albuquerque de Souza e Silva. * * This file may be distributed under the terms of the Q Public License * as defined by Trolltech AS of Norway and appearing in the file * LICENSE.QPL included in the packaging of this file. * * THIS FILE IS PROVIDED AS IS WITH NO WARRANTY OF ANY KIND, INCLUDING * THE WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR * PURPOSE. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, * INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING * FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. * */ import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; public class Main { private static final int BUFFER_SIZE = 2048; public static void copyFile(String fileIn, String fileOut) throws IOException { copyFile(new File(fileIn), new File(fileOut)); } public static void copyFile(File fileIn, File fileOut) throws IOException { InputStream is = new FileInputStream(fileIn); OutputStream os = new FileOutputStream(fileOut); copyStream(is, os); is.close(); os.close(); } public static void copyStream(InputStream is, OutputStream os) throws IOException { byte[] buf = new byte[BUFFER_SIZE]; while (true) { int len = is.read(buf); if (len == -1) return; os.write(buf, 0, len); } } }