Here you can find the source of copyFile(final File input, final File output)
Parameter | Description |
---|---|
input | The file to be read |
output | The file to be written to |
Parameter | Description |
---|---|
IOException | if anything fails. |
public static void copyFile(final File input, final File output) 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 { /**/* ww w .ja v a2 s .c om*/ * This method can be used to copy a file from one place to another. * * @param input * The file to be read * @param output * The file to be written to * @throws IOException * if anything fails. */ public static void copyFile(final File input, final File output) throws IOException { FileInputStream in = null; FileOutputStream out = null; try { in = new FileInputStream(input); out = new FileOutputStream(output); FileChannel inChannel = in.getChannel(); FileChannel outChannel = out.getChannel(); long size = inChannel.size(); inChannel.transferTo(0L, size, outChannel); } finally { try { if (in != null) { in.close(); } } catch (IOException e) { /* ignore */ } try { if (out != null) { out.close(); } } catch (IOException e) { /* ignore */ } } } }