zoukankan      html  css  js  c++  java
  • Java之ByteArrayInputStream和ByteArrayOutputStream-操作字节数组的类

    ByteArrayInputStream和ByteArrayOutputStream

      源:内存中的字节数组

      目的:内存中的字节数组

    这两个流对象不涉及底层资源的调用,操作的都是内存中的数组,所以不需要关闭,直接操作字节数组就可以了

     1 package FileDemo;
     2 
     3 import java.io.ByteArrayInputStream;
     4 import java.io.ByteArrayOutputStream;
     5 
     6 public class ByteArrayStreamDemo {
     7 
     8     /**
     9      * @param args
    10      */
    11     public static void main(String[] args) {
    12 
    13         ByteArrayInputStream bis = new ByteArrayInputStream("abcdef".getBytes());
    14         ByteArrayOutputStream bos = new ByteArrayOutputStream();
    15         int ch = 0;
    16         while ((ch = bis.read()) != -1) {
    17             bos.write(ch);
    18         }
    19         System.out.println(bos.toString());
    20     }
    21 
    22 }

    CharArratInputReader和CharArrayOutputWriter

      源:字符数组的字符流

      目的:字符数组的字符流

    StringReader和StringWriter

      源:字符串的字符流

      目的:字符串的字符流

  • 相关阅读:
    django计数器: form collections import Counter
    issubclass使用
    Python rpartition() 方法
    try...except...else高级用法
    FBV及CBV区别
    类属性及对象属性
    判断类或对象方法
    django md5
    @cached_property
    js Array 中的 map, filter 和 reduce
  • 原文地址:https://www.cnblogs.com/ysw-go/p/5311534.html
Copyright © 2011-2022 走看看