By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,279 Members | 2,248 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,279 IT Pros & Developers. It's quick & easy.

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

P: n/a
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.

Jun 20 '07 #1
Share this Question
Share on Google+
4 Replies


P: n/a
On Jun 20, 2:54 pm, j.a. harriman
<jeffrey_no_spam_al...@nospam.nospamwrote:
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

Jun 20 '07 #2

P: n/a
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.

"Jon Skeet [C# MVP]" wrote:
On Jun 20, 2:54 pm, j.a. harriman
<jeffrey_no_spam_al...@nospam.nospamwrote:
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

Jun 20 '07 #3

P: n/a
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.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"j.a. harriman" <je*******************@nospam.nospamwrote in message
news:65**********************************@microsof t.com...
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.

"Jon Skeet [C# MVP]" wrote:
>On Jun 20, 2:54 pm, j.a. harriman
<jeffrey_no_spam_al...@nospam.nospamwrote:
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


Jun 20 '07 #4

P: n/a
j.a. harriman <je*******************@nospam.nospamwrote:
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.
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.

--
Jon Skeet - <sk***@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
Jun 20 '07 #5

This discussion thread is closed

Replies have been disabled for this discussion.