title: UTF-8 character encoding in Java
body: <p>I am having some problems getting some French text to convert to UTF8 so that it can be displayed properly, either in a console, text file or in a GUI element.</p>
  
  <p>The original string is</p>
  
  <p>HANDICAP╔ES</p>
  
  <p>which is supposed to be </p>
  
  <p>HANDICAPÉES</p>
  
  <p>Here is a code snippet that shows how I am using the <a href="http://jackcess.sourceforge.net/" rel="noreferrer">jackcess</a> Database driver to read in the Acccess MDB file in an Eclipse/Linux environment.</p>
  
  <pre><code>Database database = Database.open(new File(filepath));
  Table table = database.getTable(tableName, true);
  Iterator rowIter = table.iterator();
  while (rowIter.hasNext()) {
      Map&lt;String, Object&gt; row = this.rowIter.next();
      // convert fields to UTF
      Map&lt;String, Object&gt; rowUTF = new HashMap&lt;String, Object&gt;();
      try {
          for (String key : row.keySet()) {
              Object o = row.get(key);
              if (o != null) {
                  String valueCP850 = o.toString();
                  // String nameUTF8 = new String(valueCP850.getBytes("CP850"), "UTF8"); // does not work!
                  String valueISO = new String(valueCP850.getBytes("CP850"), "ISO-8859-1");
                  String valueUTF8 = new String(valueISO.getBytes(), "UTF-8"); // works!
                  rowUTF.put(key, valueUTF8);
              }
          }
      } catch (UnsupportedEncodingException e) {
          System.err.println("Encoding exception: " + e);
      }   
  }
  </code></pre>
  
  <p>In the code you'll see where I want to convert directly to UTF8, which doesn't seem to work, so I have to do a double conversion.  Also note that there doesn't seem to be a way to specify the encoding type when using the jackcess driver.</p>
  
  <p>Thanks,
  Cam</p>