使用NIO的直接缓存区复制文件
来源:互联网 发布:php 常量定义和使用 编辑:程序博客网 时间:2024/05/16 04:51
package com.dl.test;
import java.io.*;
import java.nio.*;
import java.nio.channels.*;
public class FastCopyFile
{
static public void main( String args[] ) throws Exception {
if (args.length<2) {
System.err.println( "Usage: java FastCopyFile infile outfile" );
System.exit( 1 );
}
String infile = args[0];
String outfile = args[1];
FileInputStream fin = new FileInputStream( infile );
FileOutputStream fout = new FileOutputStream( outfile );
FileChannel fcin = fin.getChannel();
FileChannel fcout = fout.getChannel();
ByteBuffer buffer = ByteBuffer.allocateDirect( 1024 );
while (true) {
buffer.clear();
int r = fcin.read( buffer );
if (r==-1) {
break;
}
buffer.flip();
fcout.write( buffer );
}
}
}
import java.io.*;
import java.nio.*;
import java.nio.channels.*;
public class FastCopyFile
{
static public void main( String args[] ) throws Exception {
if (args.length<2) {
System.err.println( "Usage: java FastCopyFile infile outfile" );
System.exit( 1 );
}
String infile = args[0];
String outfile = args[1];
FileInputStream fin = new FileInputStream( infile );
FileOutputStream fout = new FileOutputStream( outfile );
FileChannel fcin = fin.getChannel();
FileChannel fcout = fout.getChannel();
ByteBuffer buffer = ByteBuffer.allocateDirect( 1024 );
while (true) {
buffer.clear();
int r = fcin.read( buffer );
if (r==-1) {
break;
}
buffer.flip();
fcout.write( buffer );
}
}
}
0 0
- 使用NIO的直接缓存区复制文件
- 使用NIO复制文件
- NIO的直接缓存区与非直接分缓存区
- File操作-使用NIO进行文件的读写与复制
- nio 使用的都是直接内存吗?
- NIO 复制文件。
- NIO复制文件
- java NIO复制文件
- 修改VDI文件的uid,支持新建虚拟机时直接复制使用vdi文件
- JAVA功能代码《12》----使用NIO快速复制文件
- 使用NIO与BIO复制文件性能对比
- 写日志的函数,直接复制使用
- Android直接复制使用的工具类
- Linux中带缓存的文件复制
- 不带缓存的文件复制程序
- java nio 复制文件功能
- nio快速文件复制方法
- 【Java IO】NIO复制文件
- HDU 1050 Moving Tables
- NodeJS之异步编程(一)参数传递
- 浙江大学PAT_乙级_1038. 统计同成绩学生(20)
- 虚拟存储管理
- 【HTML】文字效果
- 使用NIO的直接缓存区复制文件
- 新浪微博开发之十八(文本框)
- poj2965 The Pilots Brothers' refrigerator
- Take advantage of TCP/IP options to optimize data transmission
- Express启动方式区别
- win7(64)+httpd2.4.12+mysql5.5.20+php5.6.7环境配置记录
- LeetCode 112: Path Sum
- 安卓快速集成支付功能
- node.js学习记录(1)