FileChannel应用实例——拷贝文件transferFrom方法
生活随笔
收集整理的這篇文章主要介紹了
FileChannel应用实例——拷贝文件transferFrom方法
小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
package com.atguigu.nio;import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.nio.channels.FileChannel;public class NIOFileChannel04 {public static void main(String[] args) throws Exception {//創(chuàng)建相關(guān)流FileInputStream fileInputStream = new FileInputStream("d:\\a.png");FileOutputStream fileOutputStream = new FileOutputStream("d:\\a2.png");//獲取各個(gè)流對(duì)應(yīng)的filechannelFileChannel sourceCh = fileInputStream.getChannel();FileChannel destCh = fileOutputStream.getChannel();//使用transferForm完成拷貝destCh.transferFrom(sourceCh,0,sourceCh.size());//關(guān)閉相關(guān)通道和流sourceCh.close();destCh.close();fileInputStream.close();fileOutputStream.close();}
}
?
?
總結(jié)
以上是生活随笔為你收集整理的FileChannel应用实例——拷贝文件transferFrom方法的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: FileChannel应用实例——本地文
- 下一篇: ByteBuffer支持类型化的put和