Question

When I process a properties file with the Spanish characters ó and é, characters are displayed as ?. I tried different ways to fix this, but still fail:

  • I tried to use \uxxxx
  • I tried to use InputStreamReader with encoding UTF-8
  • I tried to convert string to bytes and then create a new String from those bytes:

    new String( val.getBytes("UTF-8"), "UTF-8")
    

Nothing worked. What should I do next to fix this issue? Japanese and Russian are still OK.

Was it helpful?

Solution

The properties file needs to be in the proper encoding. By default some IDE's like eclipse saves the content using CP1252 but you are requiring the file as UTF-8. This is also required for your java code.

If you try to use \uxxxx characters but your application by default is working with CP1252 the conversion of the escape code result in a bad character.

If you use the InputStreamReader to force the reading as UTF-8 but your code and/or your file are not using UTF-8 support result in a bad character.

If you use UTF-8 conversion of an string but your source code is CP1252 you should have the same problem.

Related previous answer about source code : Should source code be saved in UTF-8 format

  • Notepad ++ Has a menu to view the format of the file and change it in "Format" menu you should view the file as if it should be opened by other formarts or you should convert the file to other file formats like "UTF-8"
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top