title: Converting UTF-8 to ISO-8859-1 in Java
body: <p>I am reading an XML document (UTF-8) and ultimately displaying the content on a Web page using ISO-8859-1. As expected, there are a few characters are not displayed correctly, such as <code>“</code>, <code>–</code> and <code>’</code> (they display as ?). </p>
  
  <p>Is it possible to convert these characters from UTF-8 to ISO-8859-1?</p>
  
  <p>Here is a snippet of code I have written to attempt this:</p>
  
  <pre><code>BufferedReader br = new BufferedReader(new InputStreamReader(urlConnection.getInputStream(), "UTF-8"));
  StringBuilder sb = new StringBuilder();
  
  String line = null;
  while ((line = br.readLine()) != null) {
    sb.append(line);
  }
  br.close();
  
  byte[] latin1 = sb.toString().getBytes("ISO-8859-1");
  
  return new String(latin1);
  </code></pre>
  
  <p>I'm not quite sure what's going awry, but I believe it's readLine() that's causing the grief (since the strings would be Java/UTF-16 encoded?). Another variation I tried was to replace latin1 with</p>
  
  <pre><code>byte[] latin1 = new String(sb.toString().getBytes("UTF-8")).getBytes("ISO-8859-1");
  </code></pre>
  
  <p>I have read previous posts on the subject and I'm learning as I go. Thanks in advance for your help.</p>