Here you can find the source of fileCopy(File src, File dest)
Parameter | Description |
---|---|
src | a parameter |
dest | a parameter |
Parameter | Description |
---|---|
IOException | an exception |
public static void fileCopy(File src, File dest) throws IOException
//package com.java2s; /******************************************************************************* * Manchester Centre for Integrative Systems Biology * University of Manchester//from ww w . j a v a2 s . com * Manchester M1 7ND * United Kingdom * * Copyright (C) 2007 University of Manchester * * This program is released under the Academic Free License ("AFL") v3.0. * (http://www.opensource.org/licenses/academic.php) *******************************************************************************/ import java.io.*; import java.nio.channels.*; public class Main { /** * * @param src * @param dest * @throws IOException */ public static void fileCopy(File src, File dest) throws IOException { if (!dest.exists()) { final File parent = new File(dest.getParent()); if (!parent.exists() && !parent.mkdirs()) { throw new IOException(); } if (!dest.exists() && !dest.createNewFile()) { throw new IOException(); } } try (final FileInputStream is = new FileInputStream(src); final FileOutputStream os = new FileOutputStream(dest); final FileChannel srcChannel = is.getChannel(); final FileChannel dstChannel = os.getChannel()) { dstChannel.transferFrom(srcChannel, 0, srcChannel.size()); } } /** * * @param src * @param dest * @throws IOException */ public static void fileCopy(String src, String dest) throws IOException { fileCopy(new File(src), new File(dest)); } }