Solved

ascii to ebcdic file conversion trouble

Posted on 2002-03-05
6
1,156 Views
Last Modified: 2012-05-04
i am trying to convert a file from ascii to ebcdic.  the conversion process works fine, but the resulting file is all on one line.

Any help would be most appreciated:

import java.io.*;

class eToATranslator
{
     public static void main (String args[])
     {
          try
          {
               //create and input stream reader                    
               FileInputStream inputStream = new FileInputStream ("XFERCED.TXT");
               //convert from ascii to unicode
               InputStreamReader inputReader = new InputStreamReader(inputStream,"Cp500");
               //attach a buffer to it
               BufferedReader buffReader = new BufferedReader (inputReader);

               //output file in ebcdic from unicode
               OutputStreamWriter outWriter = new OutputStreamWriter(new FileOutputStream("OutputXFER2.txt"),"Cp1252");
         
               String str = null;
               while ((str = buffReader.readLine()) !=null)
               {
                    outWriter.write(str+"\n");
               }
                         
               inputReader.close();
               inputStream.close();
               outWriter.close();
          }
          catch (Exception e)
          {
               System.out.println("Exception: " + e);
          }
     }
}

0
Comment
Question by:mark_cawood
  • 4
6 Comments
 
LVL 9

Expert Comment

by:Venci75
ID: 6841619
2 suggestions:
1. use outWriter.write(str+"\r\n") instead of outWriter.write(str+"\n")
2. Use PrintWriter:
//output file in ebcdic from unicode
OutputStreamWriter outWriter = new OutputStreamWriter(new FileOutputStream("OutputXFER2.txt"),"Cp1252");
PrintWriter printWriter = new PrintWriter(outWriter);
...
printWriter.println(str+"\n");
...                        
0
 

Author Comment

by:mark_cawood
ID: 6842057
Thanks for the help.

The outWriter.write(str+"\r\n") almost works. Each line of the EBCDIC code now appears on a new line.

The problem is that each line now starts with a  character and the hex values of the end of line / new line are always the sequence 0D 0A 15

to the best of my knowledge:

0D is the EBCDIC and ASCII carriage return
0A is the ASCII line feed
15 is the EBCDIC new line

So, is the 0A in that sequence anything to worry about when this file is being processed by an ebcdic reading system? (so far i've only looked at it using UltraEdit 9)

0
 

Author Comment

by:mark_cawood
ID: 6842058
Thanks for the help.

The outWriter.write(str+"\r\n") almost works. Each line of the EBCDIC code now appears on a new line.

The problem is that each line now starts with a  character and the hex values of the end of line / new line are always the sequence 0D 0A 15

to the best of my knowledge:

0D is the EBCDIC and ASCII carriage return
0A is the ASCII line feed
15 is the EBCDIC new line

So, is the 0A in that sequence anything to worry about when this file is being processed by an ebcdic reading system? (so far i've only looked at it using UltraEdit 9)

0
Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

 

Author Comment

by:mark_cawood
ID: 6842072
see above
0
 
LVL 4

Accepted Solution

by:
m_onkey_boy earned 50 total points
ID: 6842092

Have you tried this?

outWriter.write(str);
outWriter.write(0x0D);
outWriter.write(0x15);

Even if it looks wrong in notepad, it may be valid anyway.

----------------------------------------------------
BTW - No big deal, but you are closing the same stream twice:

inputReader.close();
inputStream.close();
0
 

Author Comment

by:mark_cawood
ID: 6843914
Thanks, seems to work ok
0

Featured Post

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
mockito example issue 8 72
windows explorer path to command prompt 5 43
login jsp example 24 47
How to convert from xls to xlsx using java 7 37
After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Viewers learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…
The viewer will learn how to implement Singleton Design Pattern in Java.

775 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question