文件复制实现
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) {
}
}
}
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) {
}
}
}
相关文章推荐
- 实现文件复制命令
- C#实现大文件的分割复制
- C#实现把指定文件夹下的所有文件复制到指定路径下以及修改指定文件的后缀名
- 利用IO流对象FileInputStream,和FileOutputStream实现文件的复制的学习和理解。
- Java中实现复制文件或文件夹
- Python 实现文件复制、删除
- linux下VmwareTools安装 实现文件粘贴复制 跨平台操作
- MFC 运用CFileFind 类 递归实现文件夹的 复制 (MFC 文件操作 二)
- 海量文件复制和备份的技巧(xcopy命令实现)
- 实现文件夹或文件的复制
- 父子进程通过管道实现文件复制
- 复制一个目录下的所有文件到另外一个目录(Java实现)
- KVO实现自定义文件复制进度展示
- 怎样用Java实现创建文件并把文件复制到特定系统盘里
- 简单实现文件遍历、比较、复制功能
- 如何利用C/C++逐行读取txt文件中的字符串(可以顺便实现文本文件的复制)
- 编写一个类,该类具有统计文件长度,实现文件复制的函数。 其中复制功能函数如: void copy(string srcFileName,string targetFileName);
- C语言实现文件复制功能
- 单文件复制到指定目录和自动运行多个.bat文件实现(2012.06.05)
- 目录间复制文件的线程实现