We help IT Professionals succeed at work.

how to do memcpy() in java ?

eugeneng
eugeneng asked
on
how to copy the content of a huge byte() (byte array) to another, as we can do in c using memcpy() ?

to be more specific, for example,
byte[] ba1;
byte[] ba2 = new byte[100];

ba1 = new String("how to do memcpy in java");
 
  memcpy(ba2,ba1,ba1.length) <-- how to do this in java ?
    or
  memcpy(ba2[10],ba1,ba1.length) <-- how to do this in java ?
Comment
Watch Question

Commented:
You can use System.arraycopy(..),

System.arraycopy(Object src, int src_position, Object dst, int dst_position, int length)

>memcpy(ba2,ba1,ba1.length)
System.arraycopy(ba1, 0, ba2, 0, ba1.length);

>memcpy(ba2[10],ba1,ba1.length)
System.arraycopy(ba1, 0, ba2, 10, ba1.length);

Author

Commented:
great!! thanx a lot man.

Author

Commented:
great!! thanx a lot man.