title: How to avoid unwanted data being read from java servlet to android
body: <p>I have a Java servlet which takes some data from an android app and returns a string data back to the android app using the following code.</p>
  
  <pre><code>response.getOutputStream().write(STRING_MESSAGE.getBytes());
  </code></pre>
  
  <p>The value I pass here is read from the android activity as:</p>
  
  <pre><code>InputStream is = con.getInputStream();
  byte[] b = new byte[1024];
  while(is.read(b) != -1) {
      buffer.append(new String(b));
  }
  </code></pre>
  
  <p>The value is then converted to String using:</p>
  
  <pre><code>String result = buffer.toString();
  </code></pre>
  
  <p>But after doing so, the result has some added unwanted characters (they appear as a '?' inside a diamond shape) appended to the original string I have passed from the servlet. How can I avoid this?</p>