wood burning stoves*
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
Author

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
import java.io.*;

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 = in.read()) > -1) {
buffer.append((char)ch);
}
in.close();
return buffer.toString();
} catch (IOException e) {
e.printStackTrace();
return null;
}
}

static void writeOutput(String str) {

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


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



}


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
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

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: http://aspose.com/file-tools
 
subject: ASCII to EBCIDIC conversion error
 
Similar Threads
Convert .doc file to .txt file
FileInputStream - Replace Characters - FileInputStream
How can I get Unicode String of a String?
How a character save in 2 bytes in Java?
problem with writing file , please help