调用方式

FileChannel dstChannel;
FileChannel srcChannel;
dstChannel.transferFrom(srcChannel,0,srcChannel.size());
srcChannel.transferTo(0,srcChannel.size(),dstChannel);

函数原型:

transferFrom(ReadableByteChannel src,long position, long count)

transferTo(long position, long count,WritableByteChannel target)

注意:

1.transferFrom函数中的position参数表示目标通道中开始写数据的位置,传输数据是从src.position处开始传输

2.transferTo函数中的position参数表示源通道中开始传输数据的位置,写到target通道是从target.position处开始写

调用之前,一定要弄清楚src,target通道的position位置,否则会得到意外的结果

Java NIO:FileChannel数据传输的更多相关文章

  1. Java NIO FileChannel

    A Java NIO FileChannel is a channel that is connected to a file. Using a file channel you can read d ...

  2. JAVA NIO FileChannel 内存映射文件

      文件通道总是阻塞式的. 文件通道不能创建,只能通过(RandomAccessFile.FileInputStream.FileOutputStream)getChannel()获得,具有与File ...

  3. 【原创】java NIO FileChannel 学习笔记 FileChannel 简介

    java NIO 中FileChannel 的实现类是  FileChannelImpl,FileChannel本身是一个抽象类. 先介绍FileChannel File Channels 是线程安全 ...

  4. 【原创】java NIO FileChannel 学习笔记 FileChannel实现分析 即FileChannelImpl分析

    上文已经说了FileChannel是一个抽象类,FileChannelImpl是其实现,接下来介绍FileChannelImpl,参考代码来自OpenJDK7 首先 public class File ...

  5. 【原创】java NIO FileChannel 学习笔记 新建一个FileChannel

    首先使用FileChannel 的open方法获取一个FileChannel对象.下面这段代码是FileChannel中open方法的代码. public static FileChannel ope ...

  6. Java NIO read/write file through FileChannel

    referee:  Java NIO FileChannel A java nio FileChannel is an channel that is connected to a file. Usi ...

  7. Java NIO学习笔记五 FileChannel(文件通道)

    Java NIO FileChannel Java NIO FileChannel是连接文件的通道.使用FileChannel,您可以从文件中读取数据和将数据写入文件.Java NIO FileCha ...

  8. Java NIO 学习总结 学习手册

    原文 并发编程网(翻译):http://ifeve.com/java-nio-all/  源自 http://tutorials.jenkov.com/java-nio/index.html Java ...

  9. Java NIO学习系列二:Channel

    上文总结了Java NIO中的Buffer相关知识点,本文中我们来总结一下它的好兄弟:Channel.上文有说到,Java NIO中的Buffer一般和Channel配对使用,NIO中的所有IO都起始 ...

随机推荐

  1. Xshell不能连接Kali系统SSH的解决

    修改sshd_config文件 vim /etc/ssh/sshd_config 将#PasswordAuthentication yes的注释去掉 将#PermitRootLogin prohibi ...

  2. kali 安装redis

    wget http://download.redis.io/releases/redis-2.8.3.tar.gz    下载 tar xzf redis-2.8.3.tar.gz          ...

  3. linux学习笔记全-如何学习linux?

    简介 今天整理文件整理出了好多年前学习linux的笔记 就整理下发布在博客上怕文件形式会误删. linux入门基础对于新手而言不推荐看书!!不推荐看书!!(大牛跳过)先看视频看linuxcast的视频 ...

  4. Linux学习 - 02 使用 - Centos8 - 『更换rpm/epel包源为国内源』

    1. Centos8 - 『更换rpm/epel包源为国内源』 centos 8 默认是会读取centos.org的mirrorlist的,所以一般来说是不需要配置镜像的. 如果你的网络访问mirro ...

  5. 金九银十想面BAT?那这些JDK 动态代理的面试点你一定要知道

    一.什么是代理 代理是一种常用的设计模式,其目的就是为其他对象提供一个代理以控制对某个对象的访问.代理类负责为委托类预处理消息,过滤消息并转发消息,以及进行消息被委托类执行后的后续处理. 代理模式UM ...

  6. 宝塔Linux面板安装

    宝塔linux6.0版本是基于centos7开发的,务必使用centos7.x 系统 提示:Centos官方已宣布在2020年停止对Centos6的维护更新,各大软件开发商也逐渐停止对Centos6的 ...

  7. 01-01.单一职责原则(Single Responsibility)

    1.基本介绍 对于类来说的,就是一个类,应该只负责一项职责(一个类只管一件事). 如类A负责两个不同职责:职责1,职责2. 当职责1需求变更而改变A时,可能造成职责2执行错误,所以需要将类A的粒度分解 ...

  8. Java基础教程——变量

    变量 变量(variable)可以理解为一个"有名称的容器",用于装各种不同类型的数据.编程人员通过对变量的访问和修改,操作内存中的数据. 对变量的理解:https://www.c ...

  9. Java数组作业

    1 //输入一组数(10个),找出最大值,并给出最大值的位置 2 package test; 3 4 public class test1_1 { 5 public static double max ...

  10. Gradle DSL method not found: 'google()'

    报错信息如下:Gradle DSL method not found: 'google()'Possible causes:<ul><li>The project 'JustT ...