Java官方操纵byte数组的方式
生活随笔
收集整理的這篇文章主要介紹了
Java官方操纵byte数组的方式
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
java官方提供了一種操作字節(jié)數(shù)組的方法——內存流(字節(jié)數(shù)組流)ByteArrayInputStream、ByteArrayOutputStream
ByteArrayOutputStream——byte數(shù)組合并
/*** 將所有的字節(jié)數(shù)組全部寫入內存中,之后將其轉化為字節(jié)數(shù)組*/public static void main(String[] args) throws IOException {String str1 = "132";String str2 = "asd";ByteArrayOutputStream os = new ByteArrayOutputStream();os.write(str1.getBytes());os.write(str2.getBytes());byte[] byteArray = os.toByteArray();System.out.println(new String(byteArray));}?
ByteArrayInputStream——byte數(shù)組截取
/*** 從內存中讀取字節(jié)數(shù)組*/public static void main(String[] args) throws IOException {String str1 = "132asd";byte[] b = new byte[3];ByteArrayInputStream in = new ByteArrayInputStream(str1.getBytes());in.read(b);System.out.println(new String(b));in.read(b);System.out.println(new String(b));}?
轉載于:https://www.cnblogs.com/wangbin2188/p/11512192.html
總結
以上是生活随笔為你收集整理的Java官方操纵byte数组的方式的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: LCD1602温度显示程序设计流程
- 下一篇: java视频在线播放_Java实现视频网