Here you can find the source of copyFile(final File in, final File out)
Parameter | Description |
---|---|
in | input file |
out | output file |
Parameter | Description |
---|---|
IOException | if an I/O exception occurred |
public static void copyFile(final File in, final File out) throws IOException
//package com.java2s; import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; import java.nio.channels.FileChannel; public class Main { /**/* www . ja v a 2 s . c o m*/ * Copy the input file to output file * * @param in input file * @param out output file * @throws IOException if an I/O exception occurred */ public static void copyFile(final File in, final File out) throws IOException { FileChannel inChannel = new FileInputStream(in).getChannel(); FileChannel outChannel = new FileOutputStream(out).getChannel(); try { inChannel.transferTo(0, inChannel.size(), outChannel); } catch (IOException e) { throw e; } finally { if (inChannel != null) { inChannel.close(); } if (outChannel != null) { outChannel.close(); } } } }