Syntax error How to concatenate byte array in java?

How to concatenate byte array in java?



You ByteArrayOutputStream to write byte arrays and get the result using its toByteArray() method.

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] +" ");
      }
   }
}

Output

1 2 3 4 5 6
Updated on: 2019-07-30T22:30:21+05:30

3K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements