Descripción general y explicación del flujo de operaciones de la memoria

package cn.itcast_02;

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

/*
 * 内存操作流:用于处理临时存储信息的,程序结束,数据就从内存中消失
 *      字节数组
 *             ByteArrayInputStream
 *             ByteArrayOutputStream
 *      字符数组
 *             CharArrayReader
 *             CharArrayWriter
 *      字符串
 *             StringReader
 *             StringWriter
 * 
 */
public class 内存操作流的概述和讲解 {
    
    

	public static void main(String[] args) throws IOException {
    
    
		//写数据
		// ByteArrayOutputStream()
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		
		//写数据
          for(int x = 0 ; x < 10 ; x++) {
    
    
        	  baos.write(("hello").getBytes());
          }
          
          //释放资源
          //通过查看资源我么知道这里根本什么都没做
          baos.close();
          
          byte[] by = baos.toByteArray(); 
          //读数据
          //ByteArrayInputStream
          ByteArrayInputStream bais = new  ByteArrayInputStream(by);
          
          int bys = 0;
          while((bys = bais.read()) != -1) {
    
    
        	  System.out.print((char)bys);
          }
	}
}

Supongo que te gusta

Origin blog.csdn.net/kaszxc/article/details/108721595
Recomendado
Clasificación