码迷,mamicode.com
首页 > 其他好文 > 详细

内存操作流

时间:2016-03-14 21:36:41      阅读:185      评论: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
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!