集册 Java实例教程 使用ByteArrayInputStream读取字节数组

使用ByteArrayInputStream读取字节数组

欢马劈雪     最近更新时间:2020-01-02 10:19:05

419
使用ByteArrayInputStream读取字节数组


 //来 自 nowjava

import java.io.ByteArrayInputStream;


public class Main {


  public static void main(String[] args) {


    String str = "this is a test Example!";

    byte[] bytes = str.getBytes();


    ByteArrayInputStream bai = new ByteArrayInputStream(bytes);


    int ch;


    while ((ch = bai.read()) != -1) {

      System.out.print((char) ch);

    }//来 自 时 代 J a v a


  }

}