8.58 메모리 운영 흐름에 대한 개요 및 설명

973 단어
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
/*
 *      :           ,    ,         。
 *     :
 *   ByteArrayInputStream
 *   ByteArrayOutputStream
 *     :
 *   CharArrayReader
 *   CharArrayWriter
 *    :
 *   StringReader
 *   StringWriter
 */
public class ByteArrayStreamDemo {
 public static void main(String[] args) throws IOException {
  //    
  // ByteArrayOutputStream()
  ByteArrayOutputStream baos = new ByteArrayOutputStream();
  //    
  for (int x = 0; x < 10; x++) {
   baos.write(("hello" + x).getBytes());
  }
  //     
  //                  ,       close()
  // baos.close();
  // public byte[] toByteArray()
  byte[] bys = baos.toByteArray();
  //    
  // ByteArrayInputStream(byte[] buf)
  ByteArrayInputStream bais = new ByteArrayInputStream(bys);
  int by = 0;
  while ((by = bais.read()) != -1) {
   System.out.print((char) by);
  }
  // bais.close();
 }
}

좋은 웹페이지 즐겨찾기