convert EBCDIC String to ASCII format?

Lalchand picture Lalchand · Aug 19, 2011 · Viewed 29.3k times · Source

I am having a flat file which is pulled from a Db2 table ,the flat file contains records in both the char format as well as packed decimal format.how to convert the packed data to a java string.is there any way to convert the entire flat file to ASCII format.

Answer

pap picture pap · Aug 19, 2011

EBCDIC is a family of encodings. You'll need to know more in details which EBCDIC encoding you're after.

Java has a number of supported encodings, including:

  • IBM500/Cp500 - EBCDIC 500V1
  • x-IBM834/Cp834 - IBM EBCDIC DBCS-only Korean (double-byte)
  • IBM1047/Cp1047 - Latin-1 character set for EBCDIC hosts

Try those and see what you get. Something like:

InputStreamReader rdr = new InputStreamReader(new FileInputStream(<your file>), java.nio.Charset.forName("ibm500"));
    while((String line = rdr.readLine()) != null) {
        System.out.println(line);
}