现在的位置: 首页 > 综合 > 正文

内存操作流

2013年11月06日 ⁄ 综合 ⁄ 共 616字 ⁄ 字号 评论关闭

就是将内容写入到内存中,并从内存中取出,是用的是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);
	}
}

抱歉!评论已关闭.