旧I/O实现的通道之Flip_clear VS 输入输出通道联通
来源:互联网 发布:365抽奖软件破解版 编辑:程序博客网 时间:2024/04/30 06:17
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()); }
0 0
- 旧I/O实现的通道之Flip_clear VS 输入输出通道联通
- I/O通道
- IO 文件输入输出的通道
- I/O指令与通道指令的区别
- Java 7之异步I/O第5篇 - 异步I/O操作之通道
- I/O系统:中断、DMA、通道
- Java 新I/O 通道和缓冲器
- javaNIO之通道的简单实现
- ioctl是设备驱动程序中对设备的I/O通道进行管理的函数
- 通道
- 通道
- 通道
- 通道
- 多线程,重叠I/O,异步读写 命名通道服务器源码
- 多线程,重叠I/O,异步读写 命名通道服务器源码
- JAVA之I/O输入输出的一些注意事项
- AE中波段通道组合的实现
- Netty(四):实现通道的多路复用
- Spring模拟aop静态代理案例<一>
- Cocos2d-x-------------------------------------------Label数字文字描边
- Proxy(代理)设计模式
- READING NOTE: Object Detection by Labeling Superpixels
- Android SDK 开发范例大全 ---3.14控制不同的文字字体
- 旧I/O实现的通道之Flip_clear VS 输入输出通道联通
- Linux下安装两个mysql5.5以上版本
- 初识云计算的三种服务模式 (IaaS SaaS PaaS)
- (java)Pascal's Triangle
- myeclipse自动生成实体类
- nginx日志简单认识
- 织梦 channelartlist 按指定的typeid排序[推荐]
- 浏览器渲染原理
- 求传递闭包Warshall算法代码实现