如何在 Java 中連線位元組陣列?


使用 ByteArrayOutputStream 編寫位元組陣列並利用其 toByteArray() 方法獲取結果。

import java.io.ByteArrayOutputStream;
import java.io.IOException;
public class Tester {
   public static void main(String[] args) throws IOException {
      byte[] a = { 1,2,3};
      byte[] b = { 4,5,6};
      ByteArrayOutputStream baos = new ByteArrayOutputStream();
      baos.write(a);
      baos.write(b);
      byte[] c = baos.toByteArray();
      for(int i=0; i< c.length ; i++){
         System.out.print(c[i] +" ");
      }
   }
}

輸出

1 2 3 4 5 6

更新於: 2019-07-30

2 千次以上瀏覽

開啟你的 職業生涯

完成課程後獲得認證

開始
廣告
© . All rights reserved.