zoukankan      html  css  js  c++  java
  • 内存操作流

    可以将输出的位置设置在内存上,此时就要使用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);
    	}
    
    }
    

  • 相关阅读:
    四则运算
    读书计划
    典型用户和场景分析
    课堂练习--电梯调度
    重力解锁--用户需求调研
    书籍促销活动优惠问题
    小组开发项目--NABC分析
    梦断代码读后感之终结篇
    结对开发-求环状二维数组最大子数组
    结对开发之大数溢出
  • 原文地址:https://www.cnblogs.com/tonglin0325/p/5277090.html
Copyright © 2011-2022 走看看