Java特定块


Java特定块

import java.nio.ByteBuffer;



public class OverwriteChunkOfByteArray {

   public static void main(String args[]) {

      String str = "Hello how are you what are you doing";

      byte[] byteArray = str.getBytes();

      System.out.println("Contents of the byet array :: ");



      for(int i = 0; i<byteArray.length; i++) {

         System.out.println((char)byteArray[i]);

      }

      ByteBuffer buffer = ByteBuffer.wrap(byteArray);

      byte[] newArray = "where do you live ".getBytes();

      buffer.position(18);

      buffer.put(newArray);

      System.out.println("Contents of the byte array after replacement::");



      for(int i = 0; i<byteArray.length; i++) {

         System.out.println((char)byteArray[i]);

      }

   }

}