`

Buffered IO

    博客分类:
  • java
阅读更多
package com.bjsxt.buffer;

import java.io.BufferedInputStream;
import java.io.FileInputStream;

public class TestBufferStream1 {

	/**
	 * @param args
	 * @throws Exception 
	 */
	public static void main(String[] args) throws Exception {
		FileInputStream fis = new FileInputStream("C:\\Documents and Settings\\longlong\\My Documents\\HelloWorld.java");
		BufferedInputStream bis = new BufferedInputStream(fis);
		int c = 0;
		bis.mark(10);
		for(int i = 0; i <= 10 && (c = bis.read())!=-1; i++) {
			System.out.print((char)c + " ");
		}
		System.out.println();
		bis.reset();
		for(int i = 0; i <= 10 && (c = bis.read())!=-1; i++) {
			System.out.print((char)c + " ");
		}
		bis.close();
		fis.close();
	}

}


package com.bjsxt.buffer;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;

public class TestBufferStream2 {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
	
		try {
			BufferedWriter bw = new BufferedWriter(new FileWriter("c:\\share.txt"));
			BufferedReader br = new BufferedReader(new FileReader("C:\\Documents and Settings\\longlong\\My Documents\\HelloWorld.java"));
			String str = null;
			for(int i = 1; i <= 100; i++ ) {
				str = String.valueOf(Math.random());
				bw.write(str);
				bw.newLine();
			}
			bw.flush();
			while((str = br.readLine())!=null) {
				System.out.println(str);
			}
			bw.close();
			br.close();
		} catch (IOException e) {
			e.printStackTrace();
		}

	}

}

分享到:
评论

相关推荐

    详解C++编程中的嵌套类的声明与其中的函数使用

    可以在一个类的范围内声明另一个类。...class BufferedIO { public: enum IOError { None, Access, General }; // Declare nested class BufferedInput. class BufferedInput { public: int read

    缓冲区方式WDM驱动例子

    使用缓冲区方式(DO_BUFFERED_IO)进行用户模式和内核模式地址的数据交互。包括驱动程序和用户模式的测试程序。用DDK编译驱动,VS2008编译测试程序。

    io-buffer:以指定大小的块缓冲 IO 的流

    io缓冲区 一个非常简单的缓冲 I/O 的流。 数据以您指定大小的块提供。例子 var fs = require ( 'fs' ) ;var ioBuf = require ( 'io-buffer' ) ;// Write data to a file in 256 byte chunksvar buffered = ioBuf . ...

    写端口的驱动及测试测试

    读写端口的驱动及测试代码,使用DO_BUFFERED_IO 支持,8位,16位,及32位的读写。

    用java IO流复制文本内容(包含中文字符)

    BufferedReader/BufferedWriter 实现从字节流到字符流的读取。代码用来实现文本内容的复制!

    Netpoll 是由 字节跳动 开发的高性能 NIO(Non-blocking IO) 网络库.rar

    Thrift 支持 Buffered 和 Framed 二进制协议;Kitex Protobuf 是 Kitex 自定义的 Protobuf 消息协议,协议格式类似 Thrift;gRPC 是对 gRPC 消息协议的支持,可以与 gRPC 互通。除此之外,使用者也可以扩展自己的...

    QQ密码记录程序

    filterDeviceObject-&gt;Flags|=(targetDevice-&gt;Flags&(DO_DIRECT_IO|DO_BUFFERED_IO)); ObDereferenceObject(fileOjbect); return STATUS_SUCCESS; 2.设置完成例程 PDEVICE_EXTENSION pdx; pdx=(PDEVICE_EXTENSION)...

    webx3框架指南PDF教程附学习Demo

    该文档为官方webx框架文档,对webx进行了全面的讲解,非常实用,并附学习的Demo 为什么要用Webx而不是其它的开源框架? 现在有很多Java的Web框架可供选择,并且它们也都是免费的。例如: • Struts ...

    使用正则表达式实现网页爬虫的思路详解

    网页爬虫:就是一个程序用于在互联网中获取指定规则的数据。 思路: ...使用notepad++进行编辑,编辑内容为: ) 2.使用URL与网页建立联系 3.获取输入流,用于读取网页中的内容 ...import java.io.Buffered

    go系统编程(英文版)

    the io package, the io.Writer and io.Reader interfaces, and the bufio package that is used for buffered input and output. You will also create Go versions of the cp(1), wc(1), and dd(1) utilities. ...

    BufferedFUSE

    缓冲保险丝维护者 : Sooman Jeong ( ) 贡献者: Im ( ) 基本源代码: : 参考: Sooman Jeong, Youjip Won,“Buffered FUSE:针对用户级文件系统优化 Android IO 堆栈”,国际嵌入式系统杂志 (IJES),嵌入式和...

    swing文件拖拽

    // Get a buffered image of the selection for dragging a ghost image this.ghostImage = new BufferedImage((int) raPath.getWidth(), (int) raPath.getHeight(), BufferedImage.TYPE_INT_ARGB_PRE); ...

    数据库设计准则及方法论.docx

    CPU的执行时间、IO等待的时间和锁等待时间。 平均I/O响应时间。 支持峰值IOPS数和MPS数。 物理读和逻辑读的百分比。 有效索引读的百分比。 有效行读的百分比。 数据库设计准则及方法论全文共5页,当前为第3页。...

    python3.6.5参考手册 chm

    PEP 3151: Reworking the OS and IO exception hierarchy PEP 380: Syntax for Delegating to a Subgenerator PEP 409: Suppressing exception context PEP 414: Explicit Unicode literals PEP 3155: Qualified...

Global site tag (gtag.js) - Google Analytics