//其中能够实现编码的只有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. CURL基础

    下载单个文件: #下载单个文件,默认将输出打印到标准输出中(STDOUT)中curl http://www.centos.org # 将文件下载到本地并命名为mygettext.html curl - ...

  2. 我的Python成长之路---第三天---Python基础(12)---2016年1月16日(雾霾)

    四.函数 日常生活中,要完成一件复杂的功能,我们总是习惯把“大功能”分解为多个“小功能”以实现.在编程的世界里,“功能”可称呼为“函数”,因此“函数”其实就是一段实现了某种功能的代码,并且可以供其它代 ...

  3. Uniconnection 连 mysql 有时会断线的

    你定义localfailover:=ture.断线后会自己接上  firedac没这种功能.只有unidac有

  4. Ruby学习-第二章

    第二章 类继承,属性,类变量 1.如何声明一个子类 class Treasure < Thing 这样Thing类中的属性name,description都被Treasure继承 2.以下三种方 ...

  5. 0-1背包的动态规划算法,部分背包的贪心算法和DP算法------算法导论

    一.问题描述 0-1背包问题,部分背包问题.分别实现0-1背包的DP算法,部分背包的贪心算法和DP算法. 二.算法原理 (1)0-1背包的DP算法 0-1背包问题:有n件物品和一个容量为W的背包.第i ...

  6. win32多线程程序设计笔记(第五章)

    前面章节介绍了线程创建等过程,现在的问题是:如何在某个线程内终止另外一个正在运行的线程? windows核心编程中提到终止运行线程的方法: 1)线程函数自己返回: 2)线程通过调用ExitThread ...

  7. Android 传感器开发

    如今的智能手机都配备了各种各样的传感器,本文将介绍Android SDK提供的传感器开发接口,并通过简单实例展示怎样使用这些接口. Andriod SDK传感器相关类 android SDK提供的与传 ...

  8. Android内存之VSS/RSS/PSS/USS

    Terms VSS - Virtual Set Size 虚拟耗用内存(包含共享库占用的内存) RSS - Resident Set Size 实际使用物理内存(包含共享库占用的内存) PSS - P ...

  9. LeetCodeOJ. String to Integer (atoi)

    试题请參见: https://oj.leetcode.com/problems/string-to-integer-atoi/ 题目概述 Implement atoi to convert a str ...

  10. Sqrt(x) 牛顿迭代法

    为了实现sqrt(x),可以将问题看成是求解\(x^2-y=0\) ,即sqrt(y)=x: 牛顿法是求解方程的近似方法,给定初始点\((x0,f(x0))\),迭代公式为: #include < ...