Looking for java Answers? Try Ask4KnowledgeBase
Looking for java Keywords? Try Ask4Keywords

Java LanguageByteBuffer


Introduction

The ByteBuffer class was introduced in java 1.4 to ease working on binary data. It's especially suited to use with primitive type data. It allows the creation, but also subsequent manipulation of a byte[]s on a higher abstraction level

Syntax

  • byte[] arr = new byte[1000];
  • ByteBuffer buffer = ByteBuffer.wrap(arr);
  • ByteBuffer buffer = ByteBuffer.allocate(1024);
  • ByteBuffer buffer = ByteBuffer.allocateDirect(1024);
  • byte b = buffer.get();
  • byte b = buffer.get(10);
  • short s = buffer.getShort(10);
  • buffer.put((byte) 120);
  • buffer.putChar('a');