Solved

ascii to ebcdic file conversion trouble

Posted on 2002-03-05
6
1,183 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
What Is Transaction Monitoring and who needs it?

Synthetic Transaction Monitoring that you need for the day to day, which ensures your business website keeps running optimally, and that there is no downtime to impact your customer experience.

 

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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

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 …
This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…

717 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