javalinuxstringdb2wcs

How to set proper chracter encoding for GNU/Linux


I am creating text file in Linux server system, to upload the data to some other system. I am reading the data from DB2 database. If create the file in my development environment that is windows then there no problem all the character are coming properly.

For example If i print this line in windowsSystem.out.println(productx.getDescription().getName()); output will be 511™ Slim Fit - Rinsed Playa Jeans

The same line if it's executed on Linux system it is producing the below output

 511? Slim Fit - Rinsed Playa Jeans

If I execute the below code in that Linux system Charset charset = Charset.defaultCharset(); System.out.println("Default encoding: " + charset + " (Aliases: "+ charset.aliases() + ")"); The output is

Default encoding: ISO-8859-1 (Aliases: [819, ISO_8859-1, csISOLatin1, l1, IBM-819, 8859-1, IBM819, ISO8859-1, latin1, ISO_8859_1, ISO-8859-1:1987, cp819, iso-ir-100, 8859_1, ISO8859_1])

How to fix this problem ? Can some body help me. I tried at lot of solutions but it is not working.


Solution

  • Your default charset is Latin-1 (aka. ISO 8859-1). This charset does not seem to contain the character . Chances are your JVM runs with this default because your system is configured to use Latin-1. You make sure that both your system and your JVM use UTF-8.

    See How to get terminal's Character Encoding