内存操作流

来源:互联网 发布:幸运抽奖软件作弊 编辑:程序博客网 时间:2024/06/14 01:50

就是将内容写入到内存中,并从内存中取出,是用的是ByteArrayInputStream 和 ByteOutputStream 类:

范例:

package haizhu.com.byteArrayStream;import java.io.ByteArrayInputStream;import java.io.ByteArrayOutputStream;import java.io.IOException;public class ByteArrayDemo {public static void main(String[] args) {String str = "HELLOWORLD";ByteArrayInputStream bis = new ByteArrayInputStream(str.getBytes());ByteArrayOutputStream bos = new ByteArrayOutputStream();int temp = 0;while((temp = bis.read())!= -1){char c = (char)temp;bos.write(Character.toLowerCase(c));}String newStr = bos.toString();try{bis.close();bos.close();}catch(IOException e){e.printStackTrace();}System.out.println(newStr);}}



原创粉丝点击