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);
    	}
    
    }
    

  • 相关阅读:
    1002. 查找常用字符『简单』
    1108. IP 地址无效化『简单』
    1137. 第 N 个泰波那契数『简单』
    1154. 一年中的第几天『简单』
    1185. 一周中的第几天『简单』
    1207. 独一无二的出现次数『简单』
    暑期集训模拟赛3
    暑期集训模拟赛2
    暑期集训模拟赛1
    CF526F Pudding Monsters 【分治】
  • 原文地址:https://www.cnblogs.com/tonglin0325/p/5277090.html
Copyright © 2011-2022 走看看