ByteArrayInputStream和ByteArrayOutputStream向内存中读写数据

import java.io.*;
public class ByteArrayDemo
{
	public static void main(String[] args) 
	{
		String str="HELLOWORD";
		ByteArrayInputStream bis = null;
		ByteArrayOutputStream bos = null;
		bis=new ByteArrayInputStream(str.getBytes());
		bos=new ByteArrayOutputStream();
		int temp=0;
		while((temp=bis.read())!=-1){
			char c=(char)temp;          ///读入的数字转换为字符串
			bos.write(Character.toLowerCase(c));           ///字符串小写
		}
		///所有数据都存在ByteArrayOutputStream中了
		String newStr=bos.toString();       ///读取内容
		try{
			bis.close();
			bos.close();
		}catch(IOException e){
			e.printStackTrace();
		}
		System.out.println(newStr);
	}
}

原文地址:https://www.cnblogs.com/dengshiwei/p/4258647.html