Solved

ascii to ebcdic file conversion trouble

Posted on 2002-03-05
6
1,167 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

685 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