Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 775733
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T19:20:15+00:00 2026-05-14T19:20:15+00:00

I am having some problems getting some French text to convert to UTF8 so

  • 0

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.

The original string is

HANDICAP╔ES

which is supposed to be

HANDICAPÉES

Here is a code snippet that shows how I am using the jackcess Database driver to read in the Acccess MDB file in an Eclipse/Linux environment.

Database database = Database.open(new File(filepath));
Table table = database.getTable(tableName, true);
Iterator rowIter = table.iterator();
while (rowIter.hasNext()) {
    Map<String, Object> row = this.rowIter.next();
    // convert fields to UTF
    Map<String, Object> rowUTF = new HashMap<String, Object>();
    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);
    }   
}

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.

Thanks,
Cam

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T19:20:15+00:00Added an answer on May 14, 2026 at 7:20 pm

    New analysis, based on new information.
    It looks like your problem is with the encoding of the text before it was stored in the Access DB. It seems it had been encoded as ISO-8859-1 or windows-1252, but decoded as cp850, resulting in the string HANDICAP╔ES being stored in the DB.

    Having correctly retrieved that string from the DB, you’re now trying to reverse the original encoding error and recover the string as it should have been stored: HANDICAPÉES. And you’re accomplishing that with this line:

    String valueISO = new String(valueCP850.getBytes("CP850"), "ISO-8859-1");
    

    getBytes("CP850") converts the character ╔ to the byte value 0xC9, and the String constructor decodes that according to ISO-8859-1, resulting in the character É. The next line:

    String valueUTF8 = new String(valueISO.getBytes(), "UTF-8");
    

    …does nothing. getBytes() encodes the string in the platform default encoding, which is UTF-8 on your Linux system. Then the String constructor decodes it with the same encoding. Delete that line and you should still get the same result.

    More to the point, your attempt to create a “UTF-8 string” was misguided. You don’t need to concern yourself with the encoding of Java’s strings–they’re always UTF-16. When bringing text into a Java app, you just need to make sure you decode it with the correct encoding.

    And if my analysis is correct, your Access driver is decoding it correctly; the problem is at the other end, possibly before the DB even comes into the picture. That’s what you need to fix, because that new String(getBytes()) hack can’t be counted on to work in all cases.


    Original analysis, based on no information. :-/
    If you’re seeing HANDICAP╔ES on the console, there’s probably no problem. Given this code:

    System.out.println("HANDICAPÉES");
    

    The JVM converts the (Unicode) string to the platform default encoding, windows-1252, before sending it to the console. Then the console decodes that using its own default encoding, which happens to be cp850. So the console displays it wrong, but that’s normal. If you want it to display correctly, you can change the console’s encoding with this command:

    CHCP 1252
    

    To display the string in a GUI element, such as a JLabel, you don’t have to do anything special. Just make sure you use a font that can display all the characters, but that shouldn’t be problem for French.

    As for writing to a file, just specify the desired encoding when you create the Writer:

    OutputStreamWriter osw = new OutputStreamWriter(
        new FileOutputStream("myFile.txt"), "UTF-8");
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am having some problems getting a small piece of text to be centered
I am having some problems getting this layout to work properly in IE (both
I'm having some problems getting my object to gracefully fail out if an invalid
Im having some problems getting the Sticky Footer to work on my site. If
I'm having some problems getting ncurses' getch() to block. Default operation seems to be
I am having problems getting a function that clicks all search matched checkboxes. The
I'm having some problems integrating MS MapPoint 2009 into my WinForms .Net 2.0 application
I have been having some problems trying to get my PHP running. When I
I'm having some problems with the ranking used by fulltext search in SQL Server.
I'm having some problems with a datagridview element I'm using in VS2008. This DataGridView

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.