- 浏览: 2271511 次
- 性别:
- 来自: 成都
文章分类
- 全部博客 (357)
- J2EE (49)
- JavaScript (40)
- Spring (19)
- Struts (5)
- CSS (8)
- Hibernate (16)
- Java (67)
- DWR (4)
- JSON (3)
- XFIRE (1)
- Tomcat (1)
- Ant (2)
- 设计模式 (2)
- 经典收藏 (2)
- JSP (10)
- Linux (0)
- WebLogic (11)
- myeclipse (13)
- Buffalo (4)
- 文件上传相关 (1)
- oracle (33)
- html (6)
- JSTL (3)
- SVN (2)
- GIT (1)
- 孙卫琴(Java网络编程精解) (1)
- DOM4J (2)
- Swing (1)
- AJAX (1)
- Eclipse (5)
- 日志组件 (3)
- PowerDesigner (1)
- Jquery (22)
- IT技术开发相关网址 (1)
- Nutz (1)
- 其它 (1)
- Velocity (3)
- WebService (1)
- MySql (2)
- Android (1)
- Maven (2)
- Quartz (11)
- Lucene (1)
- springsource (1)
- Junit (1)
- Activiti (0)
最新评论
-
yzlseu:
拼凑,没有营养
Activiti进阶—分配组任务 -
zhangsenhao:
非常赞!代码很清楚
SpringMVC3.0+MyIbatis3.0(分页示例) -
xiamw2000:
分页写得不对,应该是 : order by ${orderNa ...
SpringMVC3.0+MyIbatis3.0(分页示例) -
sheertewtw:
...
SpringMVC:上传与下载 -
kingtoon:
...
XSS之xssprotect
转载:IO、文件、NIO【草案一】
http://blog.csdn.net/silentbalanceyh/archive/2010/01/25/5252265.aspx
转载:IO、文件、NIO【草案二】
http://blog.csdn.net/silentbalanceyh/archive/2010/01/25/5252280.aspx
转载:IO、文件、NIO【草案三】
http://blog.csdn.net/silentbalanceyh/archive/2010/01/26/5252285.aspx
转载:IO、文件、NIO【草案四】
http://blog.csdn.net/silentbalanceyh/archive/2010/01/25/5252301.aspx
作者写得太详细了,太好了 以及相关的,一,二,三,是了解IO,NIO最好的参考资料,
为了方便面在不能上网的时候阅读,就下载了,见附件
实战代码(文件拷贝)
最新参考资料
JAVA NIO 简介 http://alicsd.iteye.com/blog/834447
引用以上链接:
http://blog.csdn.net/silentbalanceyh/archive/2010/01/25/5252265.aspx
转载:IO、文件、NIO【草案二】
http://blog.csdn.net/silentbalanceyh/archive/2010/01/25/5252280.aspx
转载:IO、文件、NIO【草案三】
http://blog.csdn.net/silentbalanceyh/archive/2010/01/26/5252285.aspx
转载:IO、文件、NIO【草案四】
http://blog.csdn.net/silentbalanceyh/archive/2010/01/25/5252301.aspx
作者写得太详细了,太好了 以及相关的,一,二,三,是了解IO,NIO最好的参考资料,
为了方便面在不能上网的时候阅读,就下载了,见附件
实战代码(文件拷贝)
import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; import java.nio.ByteBuffer; import java.nio.channels.FileChannel; public class ReadWriteCompare { public static void main(String[] args) throws IOException { copyFileToNio("c:/dev.rar","c:/copy_dev.rar"); } public static void copyFileToNio(String sourceFilePath, String newFilePath) throws IOException { File file = new File(sourceFilePath); if(!file.exists()){ System.err.println("要拷贝的源文件不存在,请重新指定文件路径."); return; } createMkdirs(newFilePath); copyFileToNio(file,newFilePath); } public static void createMkdirs(String filePath) throws IOException{ int dirIndex = filePath.indexOf("/"); int dirIndex2 = filePath.indexOf("\\"); if(dirIndex == -1 && dirIndex2 == -1){ System.err.println("文件路径非法..."); return; } int lastIndex = filePath.lastIndexOf("/"); String dirs = filePath.substring(0,lastIndex); File file = new File(dirs); if(file.exists()){ System.err.println("文件路径不用创建..."+dirs); return; } if(file.mkdirs()){ System.out.println("文件目录创建成功..." + dirs); }else{ System.out.println("文件目录创建失败..." + dirs); } file = new File(filePath); if(!file.exists()){ file.createNewFile(); System.out.println("文件目录及文件成功..." + filePath); }else{ System.out.println("文件目录及文件已经存在"); } } private static void copyFileToNio(File sourceFile, String newFilePath) throws IOException { long timeStar = System.currentTimeMillis();//得到当前的时间 FileInputStream fileInputStream = new FileInputStream(sourceFile); FileOutputStream fileOutputStream = new FileOutputStream(newFilePath); FileChannel inChannel = fileInputStream.getChannel(); FileChannel outChannel = fileOutputStream.getChannel(); ByteBuffer byteBuffer = ByteBuffer.allocateDirect(1024); while (true) { int eof = inChannel.read(byteBuffer); if (eof == -1) break; byteBuffer.flip(); outChannel.write(byteBuffer); byteBuffer.clear(); } inChannel.close(); outChannel.close(); if(new File(newFilePath).exists()){ System.out.println("文件创建成功!"); }else{ System.out.println("文件创建失败!"); } long timeEnd = System.currentTimeMillis();//得到当前的时间 System.out.println("Read time :" + (timeEnd - timeStar) + "ms"); } }
最新参考资料
JAVA NIO 简介 http://alicsd.iteye.com/blog/834447
引用以上链接:
import java.io.FileInputStream; import java.io.FileOutputStream; import java.nio.ByteBuffer; import java.nio.channels.FileChannel; public class CopyFile { public static void main(String[] args) throws Exception { String infile = "C:\\copy.sql"; String outfile = "C:\\copy.txt"; // 获取源文件和目标文件的输入输出流 FileInputStream fin = new FileInputStream(infile); FileOutputStream fout = new FileOutputStream(outfile); // 获取输入输出通道 FileChannel fcin = fin.getChannel(); FileChannel fcout = fout.getChannel(); // 创建缓冲区 ByteBuffer buffer = ByteBuffer.allocate(1024); while (true) { // clear方法重设缓冲区,使它可以接受读入的数据 buffer.clear(); // 从输入通道中将数据读到缓冲区 int r = fcin.read(buffer); // read方法返回读取的字节数,可能为零,如果该通道已到达流的末尾,则返回-1 if (r == -1) { break; } // flip方法让缓冲区可以将新读入的数据写入另一个通道 buffer.flip(); // 从输出通道中将数据写入缓冲区 fcout.write(buffer); } } }
import java.nio.ByteBuffer; import java.nio.channels.SocketChannel; import java.nio.charset.Charset; import java.net.InetSocketAddress; import java.io.IOException; public class BaiduReader { private Charset charset = Charset.forName("GBK");// 创建GBK字符集 private SocketChannel channel; public void readHTMLContent() { try { InetSocketAddress socketAddress = new InetSocketAddress( "www.baidu.com", 80); // step1:打开连接 channel = SocketChannel.open(socketAddress); // step2:发送请求,使用GBK编码 channel.write(charset.encode("GET " + "/ HTTP/1.1" + "\r\n\r\n")); // step3:读取数据 ByteBuffer buffer = ByteBuffer.allocate(1024);// 创建1024字节的缓冲 while (channel.read(buffer) != -1) { buffer.flip();// flip方法在读缓冲区字节操作之前调用。 System.out.println(charset.decode(buffer)); // 使用Charset.decode方法将字节转换为字符串 buffer.clear();// 清空缓冲 } } catch (IOException e) { System.err.println(e.toString()); } finally { if (channel != null) { try { channel.close(); } catch (IOException e) { } } } } public static void main(String[] args) { new BaiduReader().readHTMLContent(); } }
- IO、文件、NIO【草案二】.rar (58.6 KB)
- 下载次数: 10
- IO、文件、NIO【草案三】.rar (95.6 KB)
- 下载次数: 10
- IO、文件、NIO【草案四】.rar (843 KB)
- 下载次数: 10
- IO、文件、NIO【草案一】.rar (1.1 MB)
- 下载次数: 14
发表评论
-
java json-lib & jQuery & jsonp
2016-06-30 11:31 774参考链接: 1、http://hanqunfeng.iteye ... -
随机分配算法(Intege)
2016-01-08 13:05 5140参考资料: http://blog.csdn.net/yaer ... -
XSS之xssprotect
2012-12-07 23:03 29348参考资料 1 跨网站脚本 ... -
Java之Thread(线程题)
2011-10-31 12:33 1944特别说明:java线程相关的参考了张孝祥老师的代码 参考资料 ... -
Java之ThreadLocal(Synchronized)
2011-10-31 10:10 2642参考资料 1 深入研究java.lang.ThreadLoca ... -
Java之synchronized,wait,notify结合运用示例
2011-10-26 11:54 5892场景一:要求二个线程各 ... -
Java之synchronized深入应用
2011-10-23 08:03 1906参考资料 1 java synchronized详解 http ... -
Java之Timer入门
2011-10-11 15:32 1649参考资料 1 java中timer用 ... -
Java之线程(匿名内部类)
2011-10-10 16:36 163611 Thread对象 Thread t = new Thr ... -
Java之线程(join)
2011-10-10 15:39 1422运用场景:多个线程之间 ... -
Java之线程(synchronized,wait(),notify(),notifyAll())
2011-10-10 15:03 3198参考资料 Java多线程入门大全(适用于有一定基础者) htt ... -
Java之线程(sleep,线程名)
2011-10-10 13:09 9676参考资料 1 Java线程:创建与启动 http://lava ... -
Java之线程入门
2011-10-10 11:11 1500参考资料 1 Java线程:概 ... -
java之表反向生成类
2011-09-23 16:41 3412环境:XP+JDK1.5+Oracle10g 注意事项 1 请 ... -
java之线程, NIO学习资料
2011-09-19 12:13 1092Concurrent In Java 6 第一部分 集合 ... -
Java之BigDecimal
2011-09-15 10:12 17942参考资料 1 java.math.BigDecimal的用法 ... -
java.lang.OutOfMemoryError异常解决方法
2011-08-27 16:47 2055转载:java.lang.OutOfMemoryError异常 ... -
Jcom之jp.ne.so_net.ga2.no_ji.jcom.JComException: createInstance() failed HRESULT=
2011-08-25 12:33 11637参考资料 java应用jcom将word转pdf http:/ ... -
Quartz之AnnualCalendar
2011-08-11 17:14 5765问题1 我想排除一年中 ... -
Quartz之InterruptableJob
2011-08-11 11:03 11730问题1 由于业务需要,停止Quartz中正在执行的任务 Qua ...
相关推荐
IO和NIO区别
1、Java IO_NIO 2、Java+IO.pdf
Java IO与NIO开发文档
Java IO NIO and NIO 2 英文无水印pdf pdf所有页面使用FoxitReader和PDF-XChangeViewer测试都可以打开 本资源转载自网络,如有侵权,请联系上传者或csdn删除 本资源转载自网络,如有侵权,请联系上传者或csdn...
Java IO NIO and NIO 2 英文epub 本资源转载自网络,如有侵权,请联系上传者或csdn删除 本资源转载自网络,如有侵权,请联系上传者或csdn删除
io/nio各种文件读写方法。文件压缩成jar包。
java频道\java io 与java nio区别.txt
高性能网络编程必备技能之IO与NIO阻塞分析..................
Input/output (I/O) is not a sexy subject, but it’s an important part of non-trivial applications. This book introduces you to most of Java’s I/O capabilities as of Java 8 update 51.
适合NIO初学者入门,讲解传统io与nio的区别,内有示列代码及说明图。
这是用java做的文件分割器,有两个版本,一个使用IO,另一个使用NIO,可以分割任意格式的文件。是在Linux下的eclipse中做的。
05-Java中的IO与NIO面试题(15题)-新增
JavaIO和NIO练习,主要是依据新旧JavaIO所写的一个输出输入流的Demo
java io nio nio2 java io的百科全书 mobi格式 需要kindle 软件
封装了JavaIO和NIO的接口,使得变得简单易用,在这基础上封装了一个HTTP客户端,使发送Http报文变得容易,支持http和https,用来做微信的开发最适合不过来