Here you can find the source of copyFile(File destfile, File srcfile)
Parameter | Description |
---|---|
SecurityException | an exception |
IOException | an exception |
public static void copyFile(File destfile, File srcfile) throws IOException
//package com.java2s; /*/*w w w .ja va 2 s . co m*/ * @(#)Util.java 1.62 04/06/27 * * Copyright 2004 Sun Microsystems, Inc. All rights reserved. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. */ import java.io.*; public class Main { /** * Copy source file to destination file. * * @throws SecurityException * @throws IOException */ public static void copyFile(File destfile, File srcfile) throws IOException { byte[] bytearr = new byte[512]; int len = 0; FileInputStream input = new FileInputStream(srcfile); File destDir = destfile.getParentFile(); destDir.mkdirs(); FileOutputStream output = new FileOutputStream(destfile); try { while ((len = input.read(bytearr)) != -1) { output.write(bytearr, 0, len); } } catch (FileNotFoundException exc) { } catch (SecurityException exc) { } finally { input.close(); output.close(); } } }