Package com.test.test;
Import Java.io.File;
Import Java.io.FileInputStream;
Import Java.io.FileOutputStream;
Import java.io.IOException;
Import Java.nio.channels.FileChannel;
/**
* Quickly copy Java files using NiO
*
* @author Administrator
*
*/
public class FileCopy {
@SuppressWarnings ("resource")
public static void FileCopy (file-in, file-out)
Throws IOException {
FileChannel Inchannel = new FileInputStream (in). Getchannel ();
FileChannel Outchannel = new FileOutputStream (out). Getchannel ();
try {
Inchannel.transferto (0, Inchannel.size (), Outchannel);
Original--apparently have trouble copying large files on Windows
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);
}
} finally {
if (Inchannel! = null) {
Inchannel.close ();
}
if (Outchannel! = null) {
Outchannel.close ();
}
}
}
}
Quickly copy Java files using NiO