Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / C# / June 2007

Tip: Looking for answers? Try searching our database.

File I/O for EBCDIC/packed files - read/write

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
j.a. harriman - 20 Jun 2007 14:54 GMT
Hi,
I have read the "how to's" on MSDN including this one,
http://msdn2.microsoft.com/en-us/library/36b93480.aspx, on reading/writing
files in C#, but haven't found something that I can put together that is
working.

The file I have is in EBCDIC, rec length = 250 and delimited by CRLF's.

What I want to do is open an EBCDIC file in Read/Write mode so I can read
the record, alter the data in a fixed set of positions (position 2, zero
based for 19 positions), and re-write the record (same file).

I have:
private const string FILE_NAME = "d:\\somefile.txt" // file that is in EBCDIC
// Create the reader for data.
FileStream fs = new FileStream(FILE_NAME, FileMode.Open,FileAccess.ReadWrite);
BinaryReader br = new BinaryReader(fs); // ??? use this or something else?

I am aware of the "Encoding" class, but am not certain if it's needed for
what I want to do.

I am also aware of the "MemoryStream" and "BinaryReader" classes, but not
sure which to use.

Any links to thorough examples or responses with code snippets would be most
useful.
Thanks.
Jon Skeet [C# MVP] - 20 Jun 2007 15:08 GMT
> I have read the "how to's" on MSDN including this one,http://msdn2.microsoft.com/en-us/library/36b93480.aspx, on reading/writing
> files in C#, but haven't found something that I can put together that is
> working.

<snip>

> I am aware of the "Encoding" class, but am not certain if it's needed for
> what I want to do.

Yes it is.

To read, use a StreamReader with the appropriate encoding. To write,
use a StreamWriter with the appropriate encoding.

I have an EBCDIC encoding class at http://pobox.com/~skeet/csharp/ebcdic
which lets you specify various different variants of it.

Jon
j.a. harriman - 20 Jun 2007 18:17 GMT
Jon,

Thanks for the quick reply - I will look it over and try to work on it this
week.

One question I have that hopefully you can answer:

When I specify Encoding ebcdic = Encoding.GetEncoding("IBM01140");

Is there way to see the actual table for this particular encoding, perhaps
in a *.h file?

The reason I ask, is we have an internal table that we use for ASCII-EBCDIC
conversions, based on a table from one of our vendors.  I am sure it is a
"flavor" of the IBM conversion, but I would like to compare it to what
Microsoft is doing to see if it matches our table.  It won't do me any good
to use the wrong encoding for the object.

Or I would need to know how to create my own file that I pass in to the
"GetEncoding" function which is what I'm guessing your doing with "using
JonSkeet.Ebcdic;" from your link.

Thanks.

> > I have read the "how to's" on MSDN including this one,http://msdn2.microsoft.com/en-us/library/36b93480.aspx, on reading/writing
> > files in C#, but haven't found something that I can put together that is
[quoted text clipped - 14 lines]
>
> Jon
Nicholas Paldino [.NET/C# MVP] - 20 Jun 2007 18:57 GMT
You could use Reflector to look into the encoding class, but if it is
making any calls to the underlying OS to handle the encoding (which in this
case, I imagine it is since you are requesting a code page) then you aren't
going to be able to figure it out.

   However, you can do a comparison by cycling through the range of byte
values that are valid for the encoding, and seeing what the encoding spits
out for them.  If they match your table, then use it.

   If not, you can always create your own Encoding type, derived from
Encoding, so that it encodes/decodes the bytes the way you need it to.

Signature

         - Nicholas Paldino [.NET/C# MVP]
         - mvp@spam.guard.caspershouse.com

> Jon,
>
[quoted text clipped - 45 lines]
>>
>> Jon
Jon Skeet [C# MVP] - 20 Jun 2007 19:43 GMT
> Thanks for the quick reply - I will look it over and try to work on it this
> week.
[quoted text clipped - 15 lines]
> "GetEncoding" function which is what I'm guessing your doing with "using
> JonSkeet.Ebcdic;" from your link.

The tables I use are taken from http://std.dkuug.dk/i18n/charmaps/ but
you can fairly easily use your own table if you rebuild my code. If you
look in the CharMapReader directory in the source.zip file you'll find
CharMapReader.cs which documents the file format (same as the site
linked above). You can put your own file in there, rebuild the
resources etc, and away you go.

Signature

Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet   Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.