No Data

java文件复制

原创  作者:斩雪碎光阴  发布于:2022年09月24日  阅读量:312
版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
  分类:  标签:
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.channels.FileChannel;
/**
 * 文件复制
 */
public class FileCopy {
    private static void copyFileUsingChannel(File source, File target) throws IOException {
        FileChannel sourceChannel = null;
        FileChannel destChannel = null;
        try {
            sourceChannel = new FileInputStream(source).getChannel();
            destChannel = new FileOutputStream(target).getChannel();
            destChannel.transferFrom(sourceChannel, 0, sourceChannel.size());
        }finally{
            sourceChannel.close();
            destChannel.close();
        }
    }
    public static void main(String[] args) throws IOException {
        copyFileUsingChannel(new File(\"E:\\\\资料\\\\项目.txt\"),new File(\"E:\\\\资料\\\\项目1.txt\"));
    }
}
相关文章