标签:ring cep 文件读写 操作 直接 oid getch rgs inpu
使用一个缓冲区进行读写操作:
public static void main(String[] args) throws IOException {
FileInputStream fileInputStream = new FileInputStream("1.txt");
FileChannel channel01 = fileInputStream.getChannel();
FileOutputStream fileOutputStream=new FileOutputStream("2.txt");
FileChannel channel02 = fileOutputStream.getChannel();
ByteBuffer byteBuffer = ByteBuffer.allocate(1024);
//循环读取
while(true){
//清理缓冲区 非常重要
byteBuffer.clear();
int read= channel01.read(byteBuffer);
if(read==-1){
break;
}
byteBuffer.flip();
channel02.write(byteBuffer);
}
fileInputStream.close();
fileOutputStream.close();
}
直接通过channel进行读写
public static void main(String[] args) throws IOException {
FileInputStream fileInputStream = new FileInputStream("d:\\eva.jpg");
FileOutputStream fileOutputStream = new FileOutputStream("d:\\eva2.jpg");
FileChannel channel01 = fileInputStream.getChannel();
FileChannel channel02 = fileOutputStream.getChannel();
channel02.transferFrom(channel01,0,channel01.size());
channel01.close();
channel02.close();
fileInputStream.close();
fileOutputStream.close();
}
标签:ring cep 文件读写 操作 直接 oid getch rgs inpu
原文地址:https://www.cnblogs.com/mc-74120/p/12876895.html