java copy file

try {
    // 旧地址
    FileChannel srcChannel = new FileInputStream("srcFilename").getChannel();

    // 新地址
    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) {
}

 

你可能感兴趣的:(java)