io系统
一、浅谈io系统
io系统的结构化思想是:输入-转换流-装饰器-输出。
对于字节流来说,常见的结构类为:



package com.handchina.yunmart.middleware.service;
import org.elasticsearch.common.inject.Inject;
import org.junit.Test;
import java.io.*;
/**
* Created by yq on 2016/11/18.
*/
public class IOTestServiceTest {
@Inject
private IOTestService ioTestService;
@Test
public void testFile() {
FileReader br = null;
FileWriter bw = null;
try {
String in = "file/fileDemoIn.txt";
String out = "file/fileDemoOut.txt";
br = new FileReader(in);int s;
Long start1 = System.currentTimeMillis();
bw = new FileWriter(out);
while ((s = br.read()) != -1) {
bw.write(s);
}
System.out.println("===========================复制时间:" + (System.currentTimeMillis() - start1) + "毫秒");
} catch (IOException e) {
e.printStackTrace();
} finally {
if (br != null) {
try {
br.close();
} catch (IOException e) {
e.printStackTrace();
}
}
if (bw != null) {
try {
bw.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
@Test
public void testFileDemo() {
BufferedReader br = null;
BufferedWriter bw = null;
try {
String in = "file/fileDemoIn.txt";
String out = "file/fileDemoOut.txt";
br = new BufferedReader(new FileReader(in));
StringBuilder sb = new StringBuilder();
String s = null;
Long start1 = System.currentTimeMillis();
while ((s = br.readLine()) != null) {
sb.append(s);
sb.append("\r\n");
}
System.out.println("===========================读取时间:" + (System.currentTimeMillis() - start1) + "毫秒");
bw = new BufferedWriter(new FileWriter(out));
Long start2 = System.currentTimeMillis();
bw.write(sb.toString());
bw.flush();
System.out.println("===========================写入时间:" + (System.currentTimeMillis() - start2) + "毫秒");
} catch (IOException e) {
e.printStackTrace();
} finally {
if (br != null) {
try {
br.close();
} catch (IOException e) {
e.printStackTrace();
}
}
if (bw != null) {
try {
bw.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
@Test
public void testByte() {
FileInputStream bi = null;
FileOutputStream bo = null;
try {
String in = "file/fileStreamIn.avi";
String out = "file/fileStreamOut.avi";
bi = new FileInputStream(in);
bo = new FileOutputStream(out);
byte[] buf = new byte[1024];
Long start1 = System.currentTimeMillis();
int temp = 0;
while ((temp = bi.read(buf)) != -1) {
bo.write(buf, 0, temp);
}
System.out.println("===========================复制时间:" + (System.currentTimeMillis() - start1) + "毫秒");
} catch (IOException e) {
e.printStackTrace();
} finally {
if (bi != null) {
try {
bi.close();
} catch (IOException e) {
e.printStackTrace();
}
}
if (bo != null) {
try {
bo.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
@Test
public void testByteDemo() {
BufferedInputStream bi = null;
BufferedOutputStream bo = null;
try {
String in = "file/fileStreamIn.avi";
String out = "file/fileStreamOut.avi";
bi = new BufferedInputStream(new FileInputStream(in));
bo = new BufferedOutputStream(new FileOutputStream(out));
byte[] buf = new byte[1024];
Long start1 = System.currentTimeMillis();
int temp = 0;
while ((temp = bi.read(buf)) != -1) {
bo.write(buf, 0, temp);
}
System.out.println("===========================复制时间:" + (System.currentTimeMillis() - start1) + "毫秒");
} catch (IOException e) {
e.printStackTrace();
} finally {
if (bi != null) {
try {
bi.close();
} catch (IOException e) {
e.printStackTrace();
}
}
if (bo != null) {
try {
bo.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
}
io系统的更多相关文章
- 从零开始山寨Caffe·拾贰:IO系统(四)
消费者 回忆:生产者提供产品的接口 在第捌章,IO系统(二)中,生产者DataReader提供了外部消费接口: class DataReader { public: ......... Blockin ...
- 从零开始山寨Caffe·陆:IO系统(一)
你说你学过操作系统这门课?写个无Bug的生产者和消费者模型试试! ——你真的学好了操作系统这门课嘛? 在第壹章,展示过这样图: 其中,左半部分构成了新版Caffe最恼人.最庞大的IO系统. 也是历来最 ...
- java中的io系统详解 - ilibaba的专栏 - 博客频道 - CSDN.NET
java中的io系统详解 - ilibaba的专栏 - 博客频道 - CSDN.NET 亲,“社区之星”已经一周岁了! 社区福利快来领取免费参加MDCC大会机会哦 Tag功能介绍—我们 ...
- 彻底明白Java的IO系统
java学习:彻底明白Java的IO系统 文章来源:互联网 一. Input和Output1. stream代表的是任何有能力产出数据的数据源,或是任何有能力接收数据的接收源.在Java的IO中,所有 ...
- 什么是PROFINET IO系统的实时性
实时系统是指系统能及时响应外部事件的请求,在规定的时间内完成对该事件的处理,并控制所有实时任务协调一致的运行. PROFINET IO系统的实时性就是指当有一个外部事件发生时,从输入信号到传输.到控制 ...
- Java的IO系统
Java IO系统 "对语言设计人员来说,创建好的输入/输出系统是一项特别困难的任务." 由于存在大量不同的设计方案,所以该任务的困难性是很容易证明的.其中最大的 ...
- 【Java基础系列】Java IO系统
前言 创建好的输入/输出系统不仅要考虑三种不同种类的IO系统(文件,控制台,网络连接)还需要通过大量不同的方式与他们通信(顺序,随机访问,二进制,字符,按行,按字等等). 一.输入和输出 Java的I ...
- Atitit.软件开发概念说明--io系统区--特殊文件名称保存最佳实践文件名称编码...filenameEncode
Atitit.软件开发概念说明--io系统区--特殊文件名称保存最佳实践文件名称编码...filenameEncode 不个网页title保存成个个文件的时候儿有无效字符的问题... 通常两个处理方式 ...
- Qt-QML-C++交互实现文件IO系统
QMl是没有自己的文件IO控制的,这里如果我们需要对文件进行读写操作,那么就需要去C++或者JS完成交互,交互方式有多种,由于我还没有掌握,这里就不介绍具体的交互方式了.这里就简单说明一下我的实现过程 ...
随机推荐
- PLSQL Developer安装(Oracle11g+win7_64bit)
1)安装Oracle 11g 64位 2)安装32位的Oracle客户端( instantclient-basic-win32-11.2.0.1.0)下载地址:http://www.oracle.co ...
- hdu 1301
最小生成树模板题 简单的prim算法 AC代码: #include <iostream> #include <stdio.h> #define INF 9999999 usin ...
- 解决Android SDK Manager下载太慢问题(转)
1.打开android sdk manager 2.打开tool->options,如图所示 3.将Proxy Settings 里的HTTP Proxy Server和HTTP Proxy P ...
- DropDownList获取的SelectIndex一直为0
1.想要DropDownList自动提交必须设置AutoPostBack="true"属性,下面是代码: <asp:DropDownList ID=" AutoPo ...
- [Jquery] 操作html 不常用元素方法大全
除http://www.w3school.com.cn/jquery/jquery_selectors.asp上的以外该大全应都有. 第一章 input控件篇 1.操作select 下拉框 1.1 获 ...
- progit-zh(Git中文文档)
发现好像在墙外,还是下载下来看会快点 链接: http://pan.baidu.com/s/1o8EiDMq 密码: vzf9
- 12 hdfs常用文件、目录拷贝操作、删除操作
package com.da.hbase.tool.utils; import com.da.hbase.tool.common.Const; import org.apache.hadoop.con ...
- kakfa-性能相关
1.增大partition最大连接数 kafka的集群有多个Broker服务器组成,每个类型的消息被定义为topic,同一topic内部的消息按照一定的key和算法被分区(partition)存储在不 ...
- linux pc syncy安装问题
linux pc 上安装syncy遇到的坑 pycurl安装可以指定curl-config,这个是根据自己机器libcurl安装位置确定,不在默认位置时要指定:python setup.py inst ...
- hadoop集群的故障概率估算
hadoop集群的机器数业界(国内)最大的在5000左右,是什么限制了集群的规模呢?有好几个原因. 1. namenode的内存大小限制 2. 机器故障概率随着机器数目增大而增大,通常一份数据存储在h ...