如果是单纯的大文件拷贝,这个方法最好:(jdk1.4以上)
import java.nio.channels.*    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());
    
        // Close the channels
        srcChannel.close();
        dstChannel.close();
    } catch (IOException e) {
    }

解决方案 »

  1.   

    我的是jdk1.4.1
    怎么运行后说找不到FileOutputStream 和FileInputStream当然我也加了import java.nio.channels.*
    try {
        // Create channel on the source
        FileChannel srcChannel = new FileInputStream("I:\\java\\work\\corejava2\\v2ch1\\Bounce\\Bounce.java").getChannel();    // Create channel on the destination
        FileChannel dstChannel = new FileOutputStream("I:\\java\\work\\corejava2\\v2ch1\\tg.java").getChannel();    // Copy file contents from source to destination
        dstChannel.transferFrom(srcChannel, 0, srcChannel.size());    // Close the channels
        srcChannel.close();
        dstChannel.close();
    } catch (IOException e) {
    }错误如下:
    I:\java\work\corejava2\v2ch1\Bounce\Bounce.java:61: cannot resolve symbol
    symbol: class FileInputStream 
        FileChannel srcChannel = new FileInputStream("I:\\java\\work\\corejava2\\v2ch1\\Bounce\\Bounce.java").getChannel();
                                     ^
    I:\java\work\corejava2\v2ch1\Bounce\Bounce.java:64: cannot resolve symbol
    symbol: class FileOutputStream 
        FileChannel dstChannel = new FileOutputStream("I:\\java\\work\\corejava2\\v2ch1\\tg.java").getChannel();
                                     ^
    I:\java\work\corejava2\v2ch1\Bounce\Bounce.java:72: cannot resolve symbol
    symbol: class IOException 
    } catch (IOException e) {
             ^
    3 errors
      

  2.   

    未找到FileInputStream 的定义,要import java.io.*;