集册 Java实例教程 使用FileChannel将一个文件复制到另一个文件

使用FileChannel将一个文件复制到另一个文件

欢马劈雪     最近更新时间:2020-01-02 10:19:05

526
使用FileChannel将一个文件复制到另一个文件

import java.io.FileInputStream;

import java.io.FileOutputStream;

import java.io.IOException;

import java.nio.channels.FileChannel;/*来 自 时 代 J a v a*/


public class Main {

  public void m() {

    try {

      // Create channel on the source

      FileChannel srcChannel = new FileInputStream("srcFilename").getChannel();


      // Create channel on the destination

      FileChannel dstChannel = new FileOutputStream("dstFilename").getChannel();


      // Copy file contents from source to destination

      dstChannel.transferFrom(srcChannel, 0, srcChannel.size());/** 来 自 时 代 J a v
展开阅读全文