首页 > 其他 > 详细

内存操作流

时间:2016-03-14 21:36:24      阅读:347      评论:0      收藏:0      [点我收藏+]

可以将输出的位置设置在内存上,此时就要使用ByteArrayInputStream、ByteArrayOutputStream来完成输入和输出功能。

ByteArrayInputStream主要完成将内容写入到内存中

ByteArrayOutputStream的功能主要是将内存中的数据输出

技术分享

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;

//=================================================
// File Name       :	ByteArrayStream_demo
//------------------------------------------------------------------------------
// Author          :	Common





//主类
//Function        : 	ByteArrayStream_demo
public class ByteArrayStream_demo {

	public static void main(String[] args) {
		// TODO 自动生成的方法存根
		String str = "HELLOWORD";
		ByteArrayInputStream bis = null;			//声明一个内存的输入流
		ByteArrayOutputStream bos = null;		//声明一个内存的输出流
		bis = new ByteArrayInputStream(str.getBytes());	//向内存中输入内容
		bos = new ByteArrayOutputStream();						//准备从ByteArrayInputStream中读数据
		
		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);
	}

}

 

技术分享

内存操作流

原文:http://www.cnblogs.com/tonglin0325/p/5277090.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!