zoukankan      html  css  js  c++  java
  • io 测试

    //其中能够实现编码的只有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();
    
    			}
    
    		}
    
    	}
    
    }
    


  • 相关阅读:
    DEV GridControl打印 导出
    DES加密解密类
    多例模式,保证实例的唯一性,仅适用于form窗体
    c# 计算星座
    官方Radare2书之简介
    linux & windows手机 (长期更新)
    非kali官方源中的那些优秀软件们 --- java反编译反汇编器引擎汇总(长期更新)
    常见的那些模糊不清的计算机相关概念(长期更新)
    什么是网站追踪?它为什么要追踪我?
    浅谈生活中常见的三大应用程序架构(PE、ELF、Mach-O)、五大操作系统(windows、linux、macos、android、ios)和三大cpu架构(x86、arm、mips)
  • 原文地址:https://www.cnblogs.com/james1207/p/3306300.html
Copyright © 2011-2022 走看看