旧I/O实现的通道之Flip_clear VS 输入输出通道联通
2015-12-05 17:00
267 查看
Flip_clear
联通
package com.nio; import java.io.FileInputStream; import java.io.FileOutputStream; import java.nio.ByteBuffer; import java.nio.channels.FileChannel; public class Flip_clear { public static void main(String[] args) throws Exception { copy("old", "new"); } @SuppressWarnings("resource") public static void copy(String oldFile, String newFile) throws Exception { if (oldFile == null || newFile == null) { return; } FileChannel in = new FileInputStream(oldFile).getChannel(), out = new FileOutputStream(newFile).getChannel(); ByteBuffer buff = ByteBuffer.allocate(1024);// 关乎性能 while (in.read(buff) != -1) { buff.flip(); // Prepare for writing out.write(buff); buff.clear(); // Prepare for reading } in.close(); out.close(); } }
联通
public static void main(String[] args) throws Exception { FileChannel in = new FileInputStream("old").getChannel(), out = new FileOutputStream("new").getChannel(); in.transferTo(0, in.size(), out); //或者 out.transferFrom(in, 0, in.size()); }
相关文章推荐
- Node.js 的异步 IO 性能探讨
- SQL Server误区30日谈 第22天 资源调控器可以调控IO
- mysql 数据同步 出现Slave_IO_Running:No问题的解决方法小结
- java中的Io(input与output)操作总结(一)
- GO语言的IO方法实例小结
- java中的Io(input与output)操作总结(四)
- C#路径,文件,目录及IO常见操作汇总
- SQL语句实现查询当前数据库IO等待状况
- Java进阶教程之IO基础
- java中的Io(input与output)操作总结(三)
- Java 1.0和Java 1.1 的IO类的比较
- JAVA IO API使用详解
- Java NIO和IO的区别
- Java编程中最基础的文件和目录操作方法详解
- Python中使用select模块实现非阻塞的IO
- Python通过poll实现异步IO的方法
- Python通过select实现异步IO的方法
- STM32 IO口双向问题
- 花1K内存实现高效I/O的RandomAccessFile类
- UNIX系统的IO模型