当前位置:网站首页>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();
}
}
边栏推荐
- How swiftui simulates the animation effect of view illumination increase
- 鸿蒙第三次培训
- LeetCode#20. Valid parentheses
- kali2021安装RTL8188GU无线网卡[TL-WN726N]驱动
- ACM. Hj24 chorus ●●
- The third training of Hongmeng
- 94-SQL优化案例一则(用到的写法经常是被嫌弃的)
- 75- when left join encounters subquery
- 《跟唐老师学习云网络》 - OpenStack网络实现
- Lesson 022: function: recursion is god horse after class test questions and answers
猜你喜欢

CVPR2022 | 用于重采图像的特征解耦学习与动态融合

Adblock屏蔽百度热搜
![[book delivery at the end of the article] AI has spread all over the Internet to color old photos. Here is a detailed tutorial!](/img/f0/4f237e7ab1bff9761b6092dd4ef3d9.png)
[book delivery at the end of the article] AI has spread all over the Internet to color old photos. Here is a detailed tutorial!

300. longest increasing subsequence ●●

Redis core technology and practice: learning summary directory
How to operate redis on the IntelliJ idea database console

IDC发布中国数据治理报告 亿信华辰第一
![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]](/img/2d/9a0245b87fb05ea61dbfc7922ea766.png)
Jerry's dynamic switching EQ document [chapter]

Cannot re-register id: PommeFFACompetition-v0问题解决
随机推荐
TC397 Flash
ACM. Hj24 chorus ●●
Lesson 014-15: string (see lesson 27-32 of the new version of little turtle) | after class test questions and answers
第025讲:字典:当索引不好用时 | 课后测试题及答案
查询es分页下标超过1万
Redis核心技术与实战:学习总结目录
MySQL adds (appends) prefix and suffix to a column field
92 match for several_ Recognize SQL write example
The problem that Jericho can't play the prompt tone in the music mode using the interrupt mode [chapter]
Final review of scientific and technological literature of Shandong University (Personal Crash Course)
HarmonyOS应用开发培训第二次
RuntimeError: CUDA error: CUBLAS_STATUS_EXECUTION_FAILED when calling `cublasSgemmStridedBatched( ha
90- review of several recently optimized Oracle databases
6-6 图的广度遍历-邻接矩阵实现
TC397 Flash
第014-15讲:字符串 (见小甲鱼新版27讲-32讲)| 课后测试题及答案
86- to attend & lt; SQL writing and rewriting training & gt; 's participants add a second-hand case
The machine that lies in the 52nd monthly race of Niuke (the complexity of interval assignment operation from O (n^2) to o (n))
科研热点|官宣!2022年JCR分区和影响因子发布时间确定!
Cannot re-register id: PommeFFACompetition-v0问题解决