当前位置:网站首页>NIO复制文件调用getChannel方法 transferFrom()
NIO复制文件调用getChannel方法 transferFrom()
2022-06-22 20:24:00 【kjshuan】
package kj15.niuzi.pojo;
import org.junit.Test;
import java.io.*;
import java.nio.channels.FileChannel;
public class Test01 {
@Test
public void test01() throws IOException {
FileInputStream ifo = new FileInputStream(new File("d:/abc"));
//获取文件通道
FileChannel channel = ifo.getChannel();
FileOutputStream fos=new FileOutputStream(new File("d:/bcd"));
FileChannel channel1 = fos.getChannel();
//将文件内容复制到另一个文件中
//调用transferFrom方法
channel1.transferFrom(channel,0,channel.size());
// byte[] bts=new byte[ifo.available()]; //available()方法获取文件的大小
byte[] bts=new byte[1024];
//遍历文件
//定义len为读取的字节数
int len=0;
while(ifo.read(bts)!=-1){
fos.write(bts);
}
//
//
// ifo.read(bts);
// fos.write(bts);
fos.close();
ifo.close();
}
}
边栏推荐
- Learning cloud network from teacher Tang - openstack network implementation
- 鸿蒙第三次培训
- Analysis of fegin
- 分享insert into select遇到的死锁问题(项目实战)
- 杰理之硬件上 DACL 输出,DAC 输出左右声道的声音【篇】
- TC397 Flash
- 70 root cause analysis Oracle database sudden performance problems, who will take the blame
- 74- how to remedy the loss of Oracle to MySQL for this kind of SQL optimization?
- 第020讲:函数:内嵌函数和闭包 | 课后测试题及答案
- Summary of differences between localstorage, sessionstorage and cookies
猜你喜欢

基于C语言开发工资管理系统 课程论文+源码及可执行exe文件

查询es分页下标超过1万

LeetCode 每日一题——513. 找树左下角的值

Share deadlock problems encountered in insert into select (project practice)
How to operate redis on the IntelliJ idea database console

杰理之列免晶振一拖八烧录升级【篇】

杰理之MUSIC 模式获取播放文件的目录【篇】

RealNetworks vs. 微软:早期流媒体行业之争

Campus errand management app Shaanxi Gechuang
![List of outstanding talents: no crystal vibration, one drag, eight burn and upgrade [chapter]](/img/6c/333bc95fe390234d3d06043e4bded1.png)
List of outstanding talents: no crystal vibration, one drag, eight burn and upgrade [chapter]
随机推荐
杰理之列免晶振一拖八烧录升级【篇】
Jerry's dynamic switching EQ document [chapter]
The third training of Hongmeng
软考必备资料大放送,全科目软考资料都给你备好了!
Lesson 016: sequence | after class test questions and answers
[book delivery at the end of the article] AI has spread all over the Internet to color old photos. Here is a detailed tutorial!
ACM. HJ24 合唱队 ●●
杰理之外挂 4M 的 flash 在 PC 上查看大小只有 1M 的处理方法【篇】
Lesson 027: Set: in my world, you are the only after-school test question and answer
An example of 89 Oracle SQL writing and optimizer defects
6-3 二叉树的非递归遍历
RealNetworks vs. 微软:早期流媒体行业之争
2022 a special equipment related management (elevator) examination questions and simulation examination
Is data scientist a promising profession?
Lesson 032: exception handling: you can't always be right | after class test questions and answers
Learning cloud network from teacher Tang - openstack network implementation
基于C语言开发工资管理系统 课程论文+源码及可执行exe文件
第020讲:函数:内嵌函数和闭包 | 课后测试题及答案
第019讲:函数:我的地盘听我的 | 课后测试题及答案
Android kotlin SP DP to PX