java program to convert EBCDIC to ASCII -


i wrote simple java program convert ebcdic ascii. it's not working correctly. here did

step 1: convert ascii file ebcdic using following command :   dd if=sampleinput.txt of=ebcdic.txt conv=ebcdic   sampleinput.txt has following line :  input 12 12 

step 1: generated ebcdic.txt

now, wrote following java program convert ebcdic ascii

public class cobodatafilelreadertest {   public static void main(string[] args) throws ioexception {       int line;      inputstreamreader rdr = new inputstreamreader(new fileinputstream("/users/rr/documents/workspace/ebcdic_to_ascii/ebcdic.txt"), java.nio.charset.charset.forname("ibm500"));         while((line = rdr.read()) != -1) {             system.out.println(line);     }     }  } 

it gave me wrong output, output looks :

115 97 109 112 108 101 32 49 50 32 49 50 

please let me know doing wrong , how fix it.

by calling rdr.read() read 1 byte. if want read 1 character of text instead of it's numeric representation, cast character this:

int numericchar; inputstreamreader rdr = new inputstreamreader(new fileinputstream("/users/rr/documents/workspace/ebcdic_to_ascii/ebcdic.txt"), java.nio.charset.charset.forname("ibm500")); while((numericchar = rdr.read()) != -1) {         system.out.println((char) numericchar); } 

if you'd write each numericchar file 1 byte, both files same. writing console , not file represents content numbers instead of interpreting them character.


if want output content line line this:

int numericchar; inputstreamreader rdr = new inputstreamreader(new fileinputstream("/users/rr/documents/workspace/ebcdic_to_ascii/ebcdic.txt"), java.nio.charset.charset.forname("ibm500")); while((numericchar = rdr.read()) != -1) {     system.out.print((char) numericchar); } 

this not start new line after each character.

the difference between system.out.println() , system.out.print() println start new line after printing value appending newline character \n.


Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -