Solved

ascii to ebcdic file conversion trouble

Posted on 2002-03-05
6
1,174 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
SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

 

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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Delete Android all or certain applications data programmatically 9 147
Desingning Refactoring existing code 2 45
String array comparison 4 56
how to debug htl and js pages 8 78
INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
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 will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
This video teaches viewers about errors in exception handling.
Suggested Courses

737 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