您的位置:首页 > 编程语言 > PHP开发

ByteArrayInputStream和ByteArrayOutputStream向内存中读写数据

2019-07-29 18:07 1241 查看
原文链接:https://www.geek-share.com/detail/2629042821.html
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

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: