title: Reading chinese characters into a string from a byte buffer
body: <p>So I have a char[] array that contains text and other data.</p>
  
  <p>How can I extract chinese text from the char[] array? Right now I can get english fine with</p>
  
  <pre><code>public String getString(int index, int length) {
      String str = "";
  
      for (int i = 0; i &lt; length &amp;&amp; this.data[index + i] != 0; i++)
          str = str + this.data[index + i];
  
      return str;
  }
  </code></pre>
  
  <p>then I'm trying this:</p>
  
  <pre><code>try {
      String charset = "GB18030";
      String str = new String(m.target.getBytes("UTF-16"), "GB18030");
      System.out.println(str);
      System.out.println(str.equals("大家"));
  } catch (UnsupportedEncodingException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
  }
  </code></pre>
  
  <p>m.target is a string i've gotten from the byte[] array with getString() above. I've tried various encodings and combinations of them and none of them will display the text correctly (大家) and none will return true for str.equals("大家")</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>Using this method i can successfully get the chinese characters.</p>
  
  <pre><code>public String test(int index, int length) {
      byte[] t = new byte[this.data.length];
  
      for (int i = 0; i &lt; this.data.length; i++)
          t[i] = (byte) this.data[i];
  
      try {
          return new String(t, index, length, "GB18030");
      } catch (UnsupportedEncodingException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
      }
  
      return null;
  }
  </code></pre>
  
  <p>But my question now is.. I thought the max a byte could be was 127? How can the byte array hold the high byte chinese characters? Can I safely change the buffer to byte[] instead of char[]?</p>