码迷,mamicode.com
首页 > 其他好文 > 详细

内存操作流

时间:2017-01-22 19:22:34      阅读:177      评论:0      收藏:0      [点我收藏+]

标签:ati   for   row   string   throw   stream   int   tput   input   

 

* 内存操作流:用于处理临时存储信息,程序结束后,数据就从内存中消失
*
* 字节数组:
* ByteArrayInputStream
* ByteArrayOutputStream
*
* 字符数组:
* CharArrayReader
* CharArrayWriter
*
* 字符串:
* StringReader
* StringWriter

 

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;

/*
 * 内存操作流:用于处理临时存储信息,程序结束后,数据就从内存中消失
 * 
 * 字节数组:
 * ByteArrayInputStream
 * ByteArrayOutputStream
 * 
 * 字符数组:
 * CharArrayReader
 * CharArrayWriter
 * 
 * 字符串:
 * StringReader
 * StringWriter
 * */

public class IntegerDemo {
	public static void main(String[] args) throws IOException {
		ByteArrayOutputStream baos = new ByteArrayOutputStream();

		// 写数据
		for (int i = 0; i < 10; i++) {
			baos.write(("hello" + i).getBytes());
		}

		byte bys[] = baos.toByteArray();

		// 读数据
		ByteArrayInputStream bais = new ByteArrayInputStream(bys);

		int ch;
		while ((ch = bais.read()) != -1) {
			System.out.println(ch);
		}
	}
}

 

内存操作流

标签:ati   for   row   string   throw   stream   int   tput   input   

原文地址:http://www.cnblogs.com/denggelin/p/6341064.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!