Here you can find the source of copy(File in, File out, boolean overwrite)
Parameter | Description |
---|---|
in | Input file |
out | Output file |
overwrite | If false, only overwrite if in is newer than out |
Parameter | Description |
---|---|
IOException | an exception |
public static void copy(File in, File out, boolean overwrite) throws IOException
//package com.java2s; //License from project: Apache License import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; import java.nio.channels.FileChannel; public class Main { /**/*from w ww.j a va2 s .c om*/ * Copy a file * * @param in Input file * @param out Output file * @param overwrite If false, only overwrite if in is newer than * out * @throws IOException */ public static void copy(File in, File out, boolean overwrite) throws IOException { if (overwrite || !out.exists() || (out.lastModified() < in.lastModified())) { FileChannel inChannel = new FileInputStream(in).getChannel(); FileChannel outChannel = new FileOutputStream(out).getChannel(); try { inChannel.transferTo(0, inChannel.size(), outChannel); } finally { if (inChannel != null) { inChannel.close(); } if (outChannel != null) { outChannel.close(); } } } } }