File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Java in General and the fly likes ASCII to EBCIDIC conversion error   Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "ASCII to EBCIDIC conversion error   " Watch "ASCII to EBCIDIC conversion error   " New topic

ASCII to EBCIDIC conversion error

Amar Naik
Ranch Hand

Joined: Sep 26, 2003
Posts: 43
We are have some historical data in ASCII format. We want to insert this data into our system in EBCIDIC format. I am trying to write a code to convert ASCII data to EBCIDIC data
Below is my logic

public class DcollType {

static String readInput() {

StringBuffer buffer = new StringBuffer();
try {

FileInputStream fis = new FileInputStream("ASCII.txt");
InputStreamReader isr = new InputStreamReader(fis, "ASCII") ;
Reader in = new BufferedReader(isr);
int ch;
while ((ch = > -1) {
return buffer.toString();
} catch (IOException e) {
return null;

static void writeOutput(String str) {

try {
FileOutputStream fos = new FileOutputStream("ASCII_EBCIDIC.bin");;
Writer out = new OutputStreamWriter(fos, "Cp1047" );
} catch (IOException e) {

public static void main(String[] args){
String inputstr=readInput();


This data gets produced from mainframe. the mainframe transmitted a sample file one in ASCII and another in EBCIDIC.
I used my program and converted the ASCII file to EBCIDIC. When i compared with the mainframe EBCIDIC file, there is a mismatch.

Can anybody please advise
Paul Clapham

Joined: Oct 14, 2005
Posts: 19973

This mismatch... is it that everything is totally wrong? Or is it that only a few characters are wrong (which might indicate that CP1047 was the wrong flavour of EBCDIC for your system)?

And you are trying to target only alpha fields on the mainframe, right? If there were packed decimal fields then perhaps the mainframe might have converted them into ASCII differently.

I guess I'm saying we need more information about the mismatch.
I agree. Here's the link:
subject: ASCII to EBCIDIC conversion error
jQuery in Action, 3rd edition