import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
public class ByteArrayTest{
public static void main(String[] args){
//调用transform()方法将字符串转换为大写
String tmp="abcdefghijklmnopqrstuvwhyz";
byte[] src=tmp.getBytes();//转换成字节数组,字节数组其实就是字节的集合,都是字节,因为输入流只处理字节
ByteArrayInputStream input=new ByteArrayInputStream(src);//将转换好的字节数组存放到输入流对象中
ByteArrayOutputStream output=new ByteArrayOutputStream();
//transfom(input, output);
transfom(System.in, System.out);
byte[] result=output.toByteArray();//output里面全是int字符转换成字节数组?
System.out.println(new String(result));//输出字节数组中所有字符
}
public static void transfom(InputStream in,OutputStream out){//一般都是一个字节一个字节的读取
int ch=0;
int upperChar=0;
try{
//因为char表示范围碧int小所以可以自动转换成Int
while((ch=in.read())!=-1){//会自动变化指针直到没有数据变成-1标识读取完所以数据停止循环
//ch=in.read();//上面已经执行了in.read(),指针已经移动读取了新的字节所以不能再读
upperChar=/*int)*/Character.toUpperCase(ch); //字符串字符变成大写
out.write(upperChar);//将转换后的大写数据写入,这是写到out这个对象中,存入的是个int?
}
}catch(Exception e){}
}
}