- 浏览: 844844 次
- 性别:
- 来自: 深圳
文章分类
- 全部博客 (379)
- struts (5)
- hibernate (16)
- spring (16)
- ssh (20)
- MySQL (16)
- 数据库脚本 (2)
- DownLoad (1)
- GAE (5)
- Java (103)
- LoadRunner (2)
- VF (1)
- 学习资料 (24)
- 软件使用 (21)
- 通信类 (4)
- 生活 (3)
- J2ME (1)
- 心理学 (1)
- Linux (26)
- Android (3)
- Oracle (1)
- 面向对象概念&面试准备 (11)
- ExtJs (2)
- Google Map (1)
- Flex (47)
- 算法研究 (1)
- share (20)
- python (1)
- MongoDB (7)
- centos6 (13)
- C++ (8)
- DB2 (3)
- C# (1)
- 代码片段 (24)
- Lucene (2)
- php (1)
- NodeJS (1)
- Express (1)
最新评论
-
shua1991:
已阅,我表示同意。
Eclipse统计代码行数 -
nakedou:
写的不错,挺详细的
在CentOS中使用 yum 安装MongoDB及服务器端配置 -
sjp524617477:
好方法
Eclipse统计代码行数 -
simpletrc:
<script>ale ...
Java写到.txt文件,如何实现换行 -
csdn_zuoqiang:
Apache Ftp Server,目前是1.0.4,非常好的 ...
Apache FtpServer在64位系统下服务不能启动解决方法
In a previous tip, I discussed a simple file copy algorithm in context to the best way to move a directory of files (see IO: Moving a Directory ). The algorithm I posted was something of this sort: public static void copyFile(File source, File dest) throws IOException { if(!dest.exists()) { dest.createNewFile(); } InputStream in = null; OutputStream out = null; try { in = new new FileInputStream(source); out = new FileOutputStream(dest); // Transfer bytes from in to out byte[] buf = new byte[1024]; int len; while ((len = in.read(buf)) > 0) { out.write(buf, 0, len); } } finally { if(in != null) { in.close(); } if(out != null) { out.close(); } } } One of the things to note in this algorithm is the verbosity and explicitness of the code. The code specifically defines a byte[] buffer, and sets the size to 1 kilobyte, and then it simply does kilobyte-at-a-time copies. The first potential problem with this is that the amount of optimal buffering isn't neccessarily 1 kilobyte. In addition to that, for this code to work, Java IO code must read data from the file system, bring it up into JVM memory, and then push it back down to the filesystem through Java IO. We all remember when Java 1.4 came out that it brought the java.nio package with it - most of us also remember how that was pretty much it - after that there wasn't a whole lot of noise regarding 'NIO'. It's really a shame - Java NIO has the potential to really improve performance in a lot of areas. File copies is just one of them. Here is the basic file-to-file copy algorithm re-implemented using 'NIO': public static void copyFile(File sourceFile, File destFile) throws IOException { if(!destFile.exists()) { destFile.createNewFile(); } FileChannel source = null; FileChannel destination = null; try { source = new FileInputStream(sourceFile).getChannel(); destination = new FileOutputStream(destFile).getChannel(); destination.transferFrom(source, 0, source.size()); } finally { if(source != null) { source.close(); } if(destination != null) { destination.close(); } } The first thing you'll notice about this implementation is the difference in core copying logic: byte[] buf = new byte[1024]; int len; while ((len = in.read(buf)) > 0) { out.write(buf, 0, len); } ... becomes: destination.transferFrom(source, 0, source.size()); Note that there is no reference to the buffering used or the implementation of the actual copy algorithm. This is key to the potential performance advantages of this algorithm. The 'transferFrom' algorithm has the advantage of being able to be optimized to a much higher level than most of us would want to try. For one thing, because of the design of the interacting objects, chances are good that on most platforms the copy request can be deferred directly to the underlying operating system. Let it be known that in most cases the OS will be faster at copying files than Java. Just the same, even if it can't actually defer directly to the OS for the copy, because the transferFrom algorithm is related to the underlying channel implementation, it can be optimized for the platform, context, and channel type, it can use native method calls, and do many other fancy things. Long story short, the transferFrom algorithm can be optimized and optimized and optimized (and is ). Just to verify, I filled a folder with a ton of small and large files, just to see what would happen. It seems, on average, that there is about a 33% improvement in performance (yes, 1/3rd !!!) from the rather simple copy algorithm above. Not too shabby!
http://www.javalobby.org/java/forums/t17036.html
发表评论
-
微信JS
2013-10-26 21:17 2092<div class="iteye-blog- ... -
ubuntu下MySQL用source命令导入sql文件出现乱码解决方法
2012-11-18 23:46 1565首先建立数据库的时候指明数据库编码如: CREA ... -
RandomAccessFile
2012-10-18 18:16 986public void run() { try { ... -
java中多种方式读文件
2012-10-18 16:53 985java中多种方式读文件一、多种方式读文件内容。1、按字节读取 ... -
FileChannelMain
2012-10-15 18:12 1114package scan; import java ... -
Apache FtpServer在64位系统下服务不能启动解决方法
2012-06-10 21:29 6916Apache FTPServer是一款用Java开发的 ... -
Java 集合类
2012-06-07 22:03 1793Java 集合类 1. 为什么要了解J ... -
short、int、long与byte之间的转换工具类
2012-05-31 11:05 4524/** * 各基础类型与byte之间的转换 * ... -
Linux Mint 13 配置JAVA 环境
2012-05-24 22:35 26610.1--下载 JAVA ... -
FatJar+Exe4j+Inno Setup 生成可执行的exe文件
2012-04-17 10:54 14621、fatjar 是Eclipse的一个免费的插件。它的 ... -
一个开源的高效全文检索框架(懂C语言可以进来研究下原理)
2012-04-07 23:03 1381示例地址: http://rbbs.sourcefor ... -
批量删除删除CVS文件夹
2012-04-06 16:11 2039@echo On @Rem C:/Users/XPan ... -
JPanel JTextField add Focus 获取焦点解决方案
2012-03-30 21:29 3023public class TabPagePanel ex ... -
JList List<E> Page 分页
2012-03-30 21:28 1765package view.retrieve.comps. ... -
JButton setAction的BUG
2012-03-23 10:53 1311今天在使用JButton的时候,想用setText()setI ... -
自定义JTabbedPane皮肤
2012-03-22 12:05 4740package ui; import java.awt. ... -
两个工具类
2012-03-17 21:27 894package com.retrieve.utils; ... -
两个工具类
2012-03-17 21:27 0package com.retrieve.utils; ... -
mysql、sqlserver、oracle分页,java分页统一接口实现
2012-03-13 17:56 0定义: pageStart 起始页,pageEnd 终止页, ... -
Invalid command: InetLoad::load
2012-03-06 16:41 1370Invalid command: InetLoad::load ...
相关推荐
Java IO和NIO提供了两种不同的I/O处理方式,各有优势和适用场景。IO适用于简单的I/O操作,而NIO则适合于需要高性能和高并发的应用。了解这两种I/O处理方式的区别和特点,可以帮助开发者根据具体的应用需求选择合适的...
Maven坐标:org.jboss.xnio:xnio-nio:3.8.0.Final; 标签:jboss、xnio、nio、中文文档、jar包、java; 使用方法:解压翻译后的API文档,用浏览器打开“index.html”文件,即可纵览文档内容。 人性化翻译,文档中的...
java nio ppt java.nio: High Performance I/O for Java
Servlet API和NIO(New IO)是Java编程中两个重要的概念,它们在处理网络I/O操作上有着不同的优势。Servlet API是Java服务器端编程的重要组成部分,主要用于构建动态Web应用程序,而NIO则是一种非阻塞的I/O模型,...
Maven坐标:org.apache.httpcomponents:httpcore-nio:4.4.6; 标签:apache、httpcomponents、nio、httpcore、jar包、java、中英对照文档; 使用方法:解压翻译后的API文档,用浏览器打开“index.html”文件,即可...
Java NIO:浅析IO模型 Java NIO是Java语言中用于高性能I/O操作的API,理解IO模型是学习Java NIO的基础。本文将从同步和异步的概念开始,然后介绍阻塞和非阻塞的区别,接着介绍阻塞IO和非阻塞IO的区别,最后介绍五种...
### 深入Java NIO:释放IO性能的新维度 #### 一、Java NIO的革新特性 ##### 1. 非阻塞 I/O 操作 非阻塞I/O操作是NIO的一个核心特性,它与传统的阻塞式I/O相比,在性能上有了质的飞跃。在传统的阻塞式I/O模型中,当...
全面理解 Java 网络编程 - BIO、NIO、AIO 本课程旨在帮助学生全面理解 Java 网络编程中的 BIO、NIO、AIO 三剑客,掌握 RPC 编程的基础知识,并结合实战项目巩固所学。 一、网络编程三剑客 - BIO、NIO、AIO BIO...
Maven坐标:org.apache.httpcomponents:httpcore-nio:4.4.14; 标签:apache、httpcomponents、httpcore、nio、中文文档、jar包、java; 使用方法:解压翻译后的API文档,用浏览器打开“index.html”文件,即可纵览...
在Java编程中,IO(Input/Output)和NIO(New Input/Output)是处理数据流的两种不同机制。随着JDK 1.4的引入,NIO以其高效性和灵活性成为了并发编程中不可或缺的一部分。本文将深入探讨Java中的NIO,包括它与IO的...
Java NIO: Channels and Buffers(通道和缓冲区) 标准的IO基于字节流和字符流进行操作的,而NIO是基于通道(Channel)和缓冲区(Buffer)进行操作,数据总是从通道读取到缓冲区中,或者从缓冲区写入到通道中。 ...
o Clojure对java.nio的支持。 将clojure.java.io的输入流,输出流和复制功能扩展到java.nio类。 定义新的强制功能缓冲区,字节缓冲区,字符缓冲区,双缓冲区,浮点缓冲区,整数缓冲区,长缓冲区,短缓冲区,通道,可...
Maven坐标:org.jboss.xnio:xnio-nio:3.8.4.Final; 标签:jboss、xnio、nio、jar包、java、中文文档; 使用方法:解压翻译后的API文档,用浏览器打开“index.html”文件,即可纵览文档内容。 人性化翻译,文档中的...
在"Using NIO to copy Java file fast"的例子中,开发者可能使用了以下步骤来快速复制文件: 1. 打开源文件和目标文件的FileChannel。 2. 创建一个ByteBuffer作为数据传输的中介。 3. 使用FileChannel的read()方法...
【postgres-nio】是一个专为PostgreSQL数据库设计的非阻塞、事件驱动的Swift客户端库。这个库充分利用了SwiftNIO框架,使得开发者能够在构建高性能、低延迟的应用时,享受到异步I/O的优势。SwiftNIO是Apple为Swift...
MQTT NIO 一个基于Swift NIO的MQTT 3.1.1客户端,通过NIOSSL和NIOTransportServices支持NIOTransportServices(iOS必需),WebSocket连接和TLS。 MQTT(消息队列遥测传输)是IBM开发的轻量级消息协议,于1999年...
nio java8 nio使用的总结 目录 1. NIO_NIO 与 IO 区别 NIO支持面向缓冲区的、基于通道的IO操作 IO NIO 面向流(Stream Oriented) 面向缓冲区(Buffer Oriented) 阻塞IO(Blocking IO) 非阻塞IO(NonBlocking ...
FileChannel fileChannel = new FileInputStream(file).getChannel(); // 创建一个ByteBuffer ByteBuffer buffer = ByteBuffer.allocate(1024); // 将数据从FileChannel读入buffer fileChannel.read(buffer); // ...
ReadWriter} nio的Copy方法同时从io.Reader复制到提供的nio.Buffer,然后从nio.Buffer复制到io.Writer。 这样,阻止写入不会降低io.Reader的速度。 import ( "github....
:speech_balloon: o Nio是即将推出的iOS 客户端。 目前,该项目仍在进行中。 有关更新,请在我们的矩阵房→ 。 想试一试吗? 加入公共 。入门由于仁王使用斯威夫特软件包管理器,所有你需要做的是克隆的项目,在...