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完成交互,交互方式有多种,由于我还没有掌握,这里就不介绍具体的交互方式了.这里就简单说明一下我的实现过程 ...
随机推荐
- [c#]asp.net开发微信公众平台(3)微信消息封装及反射赋值
上一篇已经搭建好整体框架,实现了入口的验证, 验证通过后就交给LookMsgType方法处理,LookMsgType方法主要是对微信发来的不同的消息进行分解,不同的类型交给业务逻辑层不同的方法处理 ...
- div有最小高度且自适应高度
DIV最小高度且自适应高度 在IE6中,如果子容器的高度超过父容器的时候,父容器会被子容器撑开,所以我们可以直接设置一个height的高度值即可.但是在IE7和firefox就不行了,它不会自动撑 ...
- ImportError No module named memcache
ImportError: No module named memcache 没有找到windows下的memcache,我们就用linux下的包来安装 先下载memcache linux下的安装包 f ...
- event对象具有的方法
// dataTransfer,toElement,fromElement,y,x,offsetY,offsetX,webkitMovementY,webkitMovementX,relatedTar ...
- Mysql 卡死的处理办理
使用用show processlist 命令进去数据库查 或者用phpMyAdmin查也可以 .
- CentOS(Linux) - SVN使用笔记(二) - 创建SVN仓库及下载仓库到本地
1.安装: 参考文章 CentOS(Linux) - SVN使用笔记(一) - 安装SVN过程及开启和关闭svn服务指令 2.创建仓库 #创建项目目录 mkdir /usr/svn#进入目录cd / ...
- php 输出昨天,今天,明天是星期几的方法
<?php //php判断某一天是星期几的方法 function getWeek($unixTime=''){ $unixTime=is_numeric($unixTime)?$unixTime ...
- android Canvas drawText 文字居中
1首先利用canvas获取画布的宽高, //获取屏幕的宽和高int width = canvas.getWidth();int height = canvas.getHeight(); 2获取文字的宽 ...
- JAVA回调函数ANDROID中典型的回调地方
在计算机中回调函数是指通过函数参数传递到其他代码类的,某一块可执行代码的引用,这以设计允许了底层代码调用者在高层定义的子程序. 在JAVA里面我们使用接口的方式来实现函数的回调. 回调的通俗就是:程序 ...
- IOS多线程 总结 -------------核心代码(GCD)
//NSObject //在子线程中执行代码 // 参数1: 执行的方法 (最多有一个参数,没有返回值) //参数2: 传递给方法的参数 [self performSelectorInBackgrou ...