怎样使用FileChannel
FileChannel定义了两个用于文件传输的方法:
1. transferTo(int position, long count, WritableByteChannel dst)
该方法是把文件从position位置开始向dst通道传送count个字节。
2. transferFrom(ReadableByteChannel src, long position, long count)
该方法是将count个字节从通道src传送到文件中,position是为文件开始写入的位置。
从FileInputStream中获得的
FileChannel对象
只支持transferTo,而从FileOutputStream中获得的
FileChannel对象
只支持tansferFrom()方法。
FileChannel sfc =
new
FileInputStream(“D://temp//from.txt”).getChannel();
FileChannel tfc =
new
FileOutputStream(“D://temp//to.txt”).getChannel();
sfc.transferTo(
0
, sfc.size(), tfc);
sfc.close();
tfc.close();
分享到:
相关推荐
经过对Flume FileChannel相关源码的分析,导致FileChannel吞吐率下降的主要原因集中于事务的提交过程——commit
7.1 打开一个FileChannel 7.2 从FileChannel通道中读取数据 7.3 向FileChannel中写入数据: 7.4 关闭FileCha
【IT十八掌徐培成】Java基础第26天-06.FileChannel-RandomAccessFile-CopyFile.zip
jruby-stdin-channel JRuby Java 扩展 gem,它从 Java System.in stdin 中提取可中断的FileChannel。 使用这个 gem,在阻塞read方法上调用close将解除阻塞,这与普通的 JRuby $stdin 。 使用close转义阻塞读取仅适用...
01-Java NIO-课程简介.mp4 02-Java NIO-概述.mp4 03-Java NIO-Channel-概述.mp4 ...13-Java NIO-Buffer-基本使用.mp4 14-Java NIO-Buffer-三个属性和类型.mp4 15-Java NIO-Buffer-分配和读写数据.mp4
1.1 阻塞 IO 2.3 FileChannel 介绍和示例 2.4 FileChannel 操作详解
13-Java NIO-Buffer-基本使用.mp4 14-Java NIO-Buffer-三个属性和类型.mp4 17-Java NIO-Buffer-缓冲区分片.mp4 18-Java NIO-Buffer-只读缓冲区.mp4 19-Java NIO-Buffer-直接缓冲区.mp4 21-Java NIO-Selector-概述....
javaSE 关于IO几种读取方式的性能比较 1.二进制数据 2.字符数据 3.压缩文件
FindFirstFile函数功能描述,及改函数的用法,示例代码
使用nio byteBuffer 实现按行读取文件(大文件) 在window/linux/macOS上均测试通过 对于中文乱码也已处理成功 完整注释,可随需求更改 有问题请邮件:mly610865580@126.com
使用FileChannel#transferTo而不使用String比较。 安装 可从。 repositories { jcenter() } compile 'net.ypresto.qtfaststartjava:qtfaststart:0.1.0' 执照 MIT许可证。 有关原始源代码的信息 该产品基于qt-
两个通道之间传输数据的方式有两种,分别是:FileChannel 的transferFrom()方法可以将数据从源通道传输到FileChannel中(这个方法在
IOAGoGo! IOAGoGo 是一个使用核心 Java 中可用的各种不同方法进行基本 IO 基准测试的库。 它是可扩展的,应该可以在 Java 所在的... 这次运行表明,使用直接分配的 ByteBuffer 和 FileChannel 读取至少 32KB,但不
SAMBox使用允许使用基于java.nio.channels.FileChannel , java.io.InputStream和java.nio.MappedByteBuffer的提供的实现之一(是否缓冲)。 通过使用java.lang.StringBuilder池最小化GC。 通过绑定视图的概念直接...
教程内容涵盖:阻塞和非阻塞IO、Channel通道、Buffer缓冲区、Selector选择器、Pipe管道、FileLock文件锁,以及Path、Files、异步FileChannel和Charset字符编码等,并通过一个多人聊天室的综合案例,把所有的NIO知识...
Java NIO系列教程(七) FileChannel Java NIO系列教程(八) SocketChannel Java NIO系列教程(九) ServerSocketChannel Java NIO系列教程(十) Java NIO DatagramChannel Java NIO系列教程(十一) Pipe Java ...
H264TrackImpl h264TrackImpl = new H264TrackImpl(new ... FileChannel fChannel = new FileOutputStream(new File("C://a.mp4")).getChannel(); mp4f.writeContainer(fChannel); fChannel.close();
FileChannel outChannel = null; try { outChannel = new FileOutputStream(outFile).getChannel(); for(String f : files){ ByteBuffer wrap = ByteBuffer.wrap("\r\n".getBytes()); outChannel.write(wrap);...
FileChannel Buffer URLConnection NIO Process HashMap LinkedHashMap TreeMap ConcurrentHashMap ConcurrentLinkedQueue ThreadPool ThreadLocal Reflection ScheduledThreadPool ...
java各类IO流的整理demo,其内包含InputStream/OutputStream BufferedReader流 FileOutputStream/FileInputStream流 PrintWriter流 DataOut/DataIn流 Object流 FileChannel类;