//其中能够实现编码的只有OutputStreamWriter和对应inputStreamReader 
package net;

import java.io.BufferedWriter;
import java.io.File;
import java.io.IOException;
import java.io.OutputStreamWriter; import java.io.FileOutputStream; import java.io.*; public class FileIoTest { public static void main(String[] args) throws IOException { FileOutputStream out = null; //只能输出二进制 byte FileOutputStream outSTr = null; BufferedOutputStream Buff = null; FileWriter fw = null; BufferedWriter bf = null; WebContent webcontent =new WebContent(); String url ="http://www.baidu.com/"; String htmlContent = webcontent.getOneHtml(url); int count = 1;// 写文件行数 try {
/****************************采用FileOutputStream方式*************************************************************/
out = new FileOutputStream(new File("D:/FileOutputStream.html")); long begin = System.currentTimeMillis(); for (int i = 0; i < count; i++) { out.write(htmlContent.getBytes()); }
out.close(); long end = System.currentTimeMillis(); System.out.println("FileOutputStream执行耗时:" + (end - begin) + " 豪秒");
/************************************采用BufferedOutputStream方式********************************************************/
outSTr = new FileOutputStream(new File("D:/BufferedOutputStream.html")); Buff = new BufferedOutputStream(outSTr); long begin0 = System.currentTimeMillis(); for (int i = 0; i < count; i++) { Buff.write(htmlContent.getBytes()); } Buff.flush(); Buff.close(); long end0 = System.currentTimeMillis(); System.out.println("BufferedOutputStream执行耗时:" + (end0 - begin0)
+ " 豪秒");
/*********************************采用FileWriter方式**********************************************************/
fw = new FileWriter("D:/FileWriter.html"); long begin3 = System.currentTimeMillis(); for (int i = 0; i < count; i++) { fw.write(htmlContent); } fw.close(); long end3 = System.currentTimeMillis(); System.out.println("FileWriter执行耗时:" + (end3 - begin3) + " 豪秒");
/************************************采用BufferWrite***********************************************************/
OutputStream o1 = new FileOutputStream("D:"+File.separator+"BufferedWriter.html");
OutputStreamWriter fw1 = new OutputStreamWriter(o1,"UTF-8"); bf = new BufferedWriter(fw1); long begin4 = System.currentTimeMillis(); for (int i = 0; i < count; i++) { bf.write(htmlContent); } fw1.flush(); fw1.close(); long end4 = System.currentTimeMillis(); System.out.println("BufferedWriter执行耗时:" + (end4 - begin4) + " 豪秒");
} catch (Exception e) { e.printStackTrace(); } finally { try { fw.close(); Buff.close(); outSTr.close(); out.close(); } catch (Exception e) { e.printStackTrace(); } } } }

io 测试的更多相关文章

  1. 用systemtap对sysbench IO测试结果的分析1

    http://www.actionsky.com/docs/archives/171  2016年5月6日  黄炎 近期在一些简单的sysbench IO测试中, 遇到了一些不合常识的测试结果. 从结 ...

  2. linux 磁盘IO测试工具:FIO (同时简要介绍dd工具测试)

    FIO是测试IOPS的非常好的工具,用来对硬件进行压力测试和验证.磁盘IO是检查磁盘性能的重要指标,可以按照负载情况分成照顺序读写,随机读写两大类. 目前主流的第三方IO测试工具有fio.iomete ...

  3. IO测试工具之fio详解

    目前主流的第三方IO测试工具有fio.iometer和Orion,这三种工具各有千秋. fio在Linux系统下使用比较方便,iometer在window系统下使用比较方便,Orion是oracle的 ...

  4. IO测试工具之fio详解(转)

    http://www.cnblogs.com/raykuan/p/6914748.html 目前主流的第三方IO测试工具有fio.iometer和Orion,这三种工具各有千秋. fio在Linux系 ...

  5. IO测试工具 - 用于IO测试 ; linux benchmarks

    IO测试工具,用于磁盘IO测试,下面进行使用列表进行记录: iozone fio dd ioping iotop iostat bonnie++ crystalDisk Atto as-ssd-ben ...

  6. 91云服务器网络带宽测试,IO测试、全国ping测试

    91yun服务器测试一键包介绍 一键包主要是为了让大家快速对服务器的基本状况有一个了解.考虑到天朝的网络出口问题,所以这个一键包更加偏向网络的测试. 影响测试耗时主要是下载,整个测试如果是能跑满100 ...

  7. Linxu IO测试软件

    fio 安装 apt-get install fio fdisk -l Device Boot Start End Blocks Id System/dev/sda1 * 2048 968390655 ...

  8. ---dd io测试

    下面是一个简单测试,虽然不够准确但是简单立即可行, 当前目录的IO写读测试: (写) dd if=/dev/zero of=test bs=64k count=16k conv=fdatasync ( ...

  9. mongodb的IO测试工具 mongoperf

    之前没发现mongoperf这个工具,测试IO的状态用的是iostat来进行观察. mongoperf < myjsonconfigfile  echo "{nThreads:2,fi ...

随机推荐

  1. zabbix 邮件告警配置

    使用外部邮箱账号发送报警邮件设置 一.关闭sendmail或者postfix service sendmail stop #关闭 chkconfig sendmail off #禁止开机启动 serv ...

  2. ZOJ 2794 Just Pour the Water 【矩阵快速幂】

    给你n个杯子,每次有特定的到水规则,倒m次请问最后每个被子里还有多少水 我们很容易发现每次变化的规则相同,那么可以set 一个矩阵存放 然后多次倒水就相当于矩阵相乘,在m 范围达到(1<= M  ...

  3. BNU 4067 求圆并

    好久没写过单组数据的题目了 QAQ 赤裸裸的模板题 #include <cstdio> #include <cstring> #include <iostream> ...

  4. printk

    printk的日志级别定义如下(在linux/kernel.h中): #define KERN_EMERG "<0>"/*紧急事件消息,系统崩溃之前提示,表示系统不可用 ...

  5. oschina开源硬件其它开源,开源硬件

    硬件驱动/工具 25Linux内核 101桌面环境 40开源字体 58嵌入式操作系统 33输入法 110开源硬件 57开源图书 5开源家居 17物联网 87开源货币/比特币 32NASA 开源项目 1 ...

  6. sql2008R2sp1局域网镜像环境实操(无见证服务器)

    环境介绍: 我的电脑:sql2008r2sp1_32 129.186.110.37 OS win2003 SP2 Enterprise     做主体服务器, 暂叫ServerA 服务器:    sq ...

  7. KeyValuePair用法(转)

    转载自:http://blog.sina.com.cn/s/blog_9741eba801016w61.html C# KeyValuePair<TKey,TValue>的用法.结构体,定 ...

  8. BZOJ AC 200题留念

    话说本来想200AC就把题目总结一下...但是我现在挺懒的..不想弄...以后再来吧.

  9. win7下:MySQL-Front的下载与安装

    MySQL-Front是mysql数据库的可视化图形工具,因为它是“实时”的应用软件,它可以提供比系统内建在PHP和HTML上更为精炼的用户界面. 参考百度经验:http://jingyan.baid ...

  10. jetty插件开发配置

    <plugins> <!-- jetty插件 --> <plugin> <groupId>org.mortbay.jetty</groupId&g ...