Here you can find the source of copyFile(File in, File out)
Parameter | Description |
---|---|
IOException | an exception |
public static void copyFile(File in, File out) throws IOException
//package com.java2s; //License from project: Open Source 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 va 2 s .c o m*/ * Kopieert een file, NIO * * @throws IOException */ public static void copyFile(File in, File out) throws IOException { try (FileInputStream fin = new FileInputStream(in); FileChannel inChannel = fin.getChannel(); FileOutputStream fout = new FileOutputStream(out); FileChannel outChannel = fout.getChannel()) { // fix copy bestanden groter dan 64MB (zie link) // // magic number for Windows, 64Mb - 32Kb) // int maxCount = (64 * 1024 * 1024) - (32 * 1024); // long size = inChannel.size(); // long position = 0; // while (position < size) { // position += // inChannel.transferTo(position, maxCount, outChannel); inChannel.transferTo(0, inChannel.size(), outChannel); } catch (IOException e) { throw e; } } }