小练习:nio读写文件,将fileread中的内容读取到filewrite中

        try {
//创建输入通道
FileInputStream fis = new FileInputStream("F:/iotest/readfile.txt");
FileChannel readChannel = fis.getChannel();
//创建缓冲区
ByteBuffer buffer = ByteBuffer.allocate();
//创建输出通道
FileOutputStream fos = new FileOutputStream("F:/iotest/filewrite.txt");
FileChannel writeChannel = fos.getChannel(); while (true) {
buffer.clear();
//将文件内容读到缓冲区中
int mark = readChannel.read(buffer);
if (mark==-) {
break;
}
buffer.flip();
writeChannel.write(buffer);
} } catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

代码运行前:

readfile:

filewrite:

代码运行后:

readfile:

filewrite:

最新文章

  1. String split
  2. cms修改栏目单页样式错位调整
  3. FtpWebRequest FTP异步下载、异步上传文件
  4. 阿里云安装nginx 和 php-fpm
  5. makefile实例(2)-多个文件实例
  6. flask+gevent+gunicorn+nginx 初试
  7. Spring Security(14)——权限鉴定基础
  8. LAMP 实现全过程及wordpress的搭建
  9. 第五节:SignalR大杂烩(与MVC融合、全局的几个配置、跨域的应用、C/S程序充当Client和Server)
  10. CodeForces 528D Fuzzy Search 多项式 FFT
  11. LeetCode算法题-Best Time to Buy and Sell Stock II
  12. https证书随记
  13. 《从零玩转python+人工智能-3》120,122节课深度优先疑问解答
  14. & 引用传值
  15. Abp问题解决集合1
  16. (转载)通向架构师的道路(第四天)之Tomcat性能调优-让小猫飞奔
  17. 【转】簡單講講 USB Human Interface Device
  18. Android——Activity去除标题栏和状态栏
  19. 大数据学习资料之SQL与NOSQL数据库
  20. InnoDB: The innodb_system data file 'ibdata1' must be writable错误

热门文章

  1. 【ecfinal2019热身赛】B题
  2. XPath 爬虫解析库
  3. JavaScript 中call()、 apply()、 bind()改变this指向理解
  4. Selenium(十一)使用EXCEL读取用户数据和生成测试报表
  5. Mongo Backup
  6. jQuery和原生JS的对比
  7. Python 10.1.1
  8. 001_UCOSIII引入原因
  9. InputStreamReader 和 FileReader联系与区别
  10. c实现双向链表