Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

convert EBCDIC String to ASCII format?

Tags:

java

ebcdic

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.

like image 329
Lalchand Avatar asked Aug 19 '11 10:08

Lalchand


2 Answers

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);
}
like image 109
pap Avatar answered Sep 19 '22 08:09

pap


Read the file as a String, write it as EBCDIC. Use the OutputStreamWriter and InputStreamWriter and give the encoding in the constructor.

like image 25
Daniel Avatar answered Sep 21 '22 08:09

Daniel