title: How to store and read a String out of a fixed-length byte array?
body: <p>I have a byte array of a fixed length, and I want to store a String in it. Something like:</p>
  
  <pre><code>byte[] dst = new byte[512];
  String foo = "foo";
  byte[] src = foo.getBytes("utf-8");
  
  for (int i = 0; i &lt; src.length; i++) {
      dst[i] = src[i];
  }
  </code></pre>
  
  <p>But when I want to read the string value back out of dst, there's no way to know where the string terminates (guess there's no notion of null terminators in java?). Do I have to store the length of the string in the byte array, read it out separately to know how many bytes to read from the byte array?</p>