Skip to Content

How to read a data written with a different encoding.

Estimated Reading Time: 1 Minutes

If you need to read data from a file written in a different encoding than the default you can use the attached java function to translate the data from the source encoding to the destination encoding.  The attached COBOL program reads a sequential file written in UTF-8 and translates it to Cp1252.  Here are the steps to run this sample:

1. Compile the COBOL source code using "iscc readfile.cbl"

2. Compile the Java source code using ""%ISCOBOL_JDK_ROOT%\bin\javac" ENCODE.java

3. Run using "iscrun READFILE".   The output should look like this:

Before conversion: This file is written into UTF8 encoding.
?? ?? ?² ?  â?¬ ?¬ ??
Hola Se?±or!
?¿C??mo est?¡s?
Ti piace il caff???

After conversion: ?This file is written into UTF8 encoding.
è é ò à ? ì ù
Hola Señor!
¿Cómo estás?
Ti piace il caffè?

How to read a data written with a different encoding.
  • Attached Files
  • KB#254-EncodingConversion.zip (1.49 KB) 7