内存操作流

* 内存操作流:用于处理临时存储信息,程序结束后,数据就从内存中消失
*
* 字节数组:
* 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);
		}
	}
}
原文地址:https://www.cnblogs.com/denggelin/p/6341064.html