java中的内存操作流

来源:互联网 发布:腾讯视频for mac官方 编辑:程序博客网 时间:2024/06/06 05:26

前面的一些博客中提到输出和输入都是从文件中来的,当然,也卡么一将输出的位置设置在内存上面,

此时要使用ByteArrayInputStream  、ByteArrayOutputStream来完成输入和输出的功能的,

ByteArrayInputStream的主要完成将内容写入到内存中,而ByteArrayOutPutStream的功能主要是将内存中的数据进行输出


package excise;import   java.io.ByteArrayInputStream;import  java.io.ByteArrayOutputStream;public class ByteArrayDemo1 {public static void main(String args[])throws Exception{String str="MY NAME  IS ZHOUMEIXU";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));}String newStr=bos.toString();bis.close();bos.close();System.out.println(newStr);}}


0 0
原创粉丝点击