您的位置:首页 > 其它

文件复制实现

2007-06-29 13:25 288 查看
文件复制实现(已经测试)

import java.io.*;
import java.nio.*;
import java.nio.channels.*;

public class Copy{
public static void main(String argv[]){
if(argv.length!=2){
System.out.println("usage>java Copy srcfilename destfilename");
System.exit(0);

}
try {
// Create channel on the source
FileChannel srcChannel = new FileInputStream(argv[0]).getChannel();

// Create channel on the destination
FileChannel dstChannel = new FileOutputStream(argv[1]).getChannel();

// Copy file contents from source to destination
dstChannel.transferFrom(srcChannel, 0, srcChannel.size());

// Close the channels
srcChannel.close();
dstChannel.close();
} catch (IOException e) {
}
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: