可以将输出的位置设置在内存上,此时就要使用ByteArrayInputStream、ByteArrayOutputStream来完成输入和输出功能。
ByteArrayInputStream主要完成将内容写入到内存中
ByteArrayOutputStream的功能主要是将内存中的数据输出

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
//=================================================
// File Name : ByteArrayStream_demo
//------------------------------------------------------------------------------
// Author : Common
//主类
//Function : ByteArrayStream_demo
public class ByteArrayStream_demo {
public static void main(String[] args) {
// TODO 自动生成的方法存根
String str = "HELLOWORD";
ByteArrayInputStream bis = null; //声明一个内存的输入流
ByteArrayOutputStream bos = null; //声明一个内存的输出流
bis = new ByteArrayInputStream(str.getBytes()); //向内存中输入内容
bos = new ByteArrayOutputStream(); //准备从ByteArrayInputStream中读数据
int temp = 0;
while((temp=bis.read()) != -1){
char c = (char)temp; //将读取的数字变为字符
bos.write(Character.toLowerCase(c)); //将字符变为小写
}
String newStr = bos.toString(); //取出内容
try{
bis.close();
bos.close();
}catch(IOException e){
e.printStackTrace();
}
System.out.println(newStr);
}
}
