📄 字节数组输入流中所读取的英文字母变成大写字母.txt
字号:
import java.io.*;
public class ByteArrayStreamDemo{
public static void main(String args[]) throws Exception
{
String s = "hello world";
byte [] b = s.getBytes();
ByteArrayInputStream bis = new ByteArrayInputStream(b);
ByteArrayOutputStream bos = new ByteArrayOutputStream();
transform(bis,bos);
//返回一个字节数组,并把字节数组中的所有数据转换成字符串输出
System.out.println(bos.toString());
bis.close();
bos.close();
}
public static void transform(InputStream is, OutputStream os) throws Exception{
int ch;
while( ( ch =is.read() ) != -1 ){ //判断是否结束
int upperCh = (Character.toUpperCase((char)ch)); //字符包装类Character有一//个方法toUpperCase可以将字符变为大写,然后再用
//到强制类型转换
os.write(upperCh);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -