17.字节数组流(只做了解)

//字节的数组流
public class ByteArrayDemo {
    
    public static void main(String[] args) throws Exception {
        
        //字节数组输出流:程序 -->内存
        ByteArrayOutputStream bos = new ByteArrayOutputStream();
        bos.write("ABCDE".getBytes());
        
        //要使用临时存储的数据
        byte[] buffer = bos.toByteArray();
        
        //字节数组输入流:内存-->程序
        ByteArrayInputStream bis = new ByteArrayInputStream(buffer);
        byte[] bys = new byte[5];
        int len = -1;
        while((len = bis.read(bys)) != -1){
            System.out.println(new String(bys,0,len));
        }
        bis.close();
        bos.close();
    }
}

你可能感兴趣的:(17.字节数组流(只做了解))