您当前的位置: 首页 > 学无止境 > 心得笔记 网站首页心得笔记
【第12章:JAVA IO】_内存操作流
发布时间:2020-12-28 13:37:49编辑:雪饮阅读()
ByteArrayInputStream字节数组输入流在内存中创建一个字节数组缓冲区,从输入流读取的数据保存在该字节数组缓冲区中。
ByteArrayOutputStream 对byte类型数据进行写入的类 相当于一个中间缓冲层,将类写入到文件等其他outputStream。它是对字节进行操作,属于内存操作流
import java.io.*;
public class Hello{
public static void main(String args[]){
String str="HELLO KASUMI";
//字节数组输入流
ByteArrayInputStream bis=new ByteArrayInputStream(str.getBytes());
//字节数组输出流
ByteArrayOutputStream bos=new ByteArrayOutputStream();
int temp=0;
while((temp=bis.read())!=-1){
char c=(char)temp;
//Character.toLowerCase将字符转换为小写
bos.write(Character.toLowerCase(c));
}
String newStr=bos.toString();
try{
bis.close();
bos.close();
}
catch(IOException e){
e.printStackTrace();
}
System.out.println(newStr);
}
};
关键字词:java,内存