473,382 Members | 1,349 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

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

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
4 6456
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: Hans-Joachim Widmaier | last post by:
Hi all. Handling files is an extremely frequent task in programming, so most programming languages have an abstraction of the basic files offered by the underlying operating system. This is...
6
by: Sebastian Kemi | last post by:
How should a write a class to a file? Would this example work: object *myobject = 0; tfile.write(reinterpret_cast<char *>(myobject), sizeof(*object)); / sebek
0
by: Scott Cadreau | last post by:
I have EBCDIC text files that I convert to comma delimited ASCII files for load into a database system. There are a wide variety of "fields" that come in the raw files (e.g....
14
by: nic977 | last post by:
I am asked to write a simple program to displays the last n lines from a given text file. But I have no ideas how C defines a "line" in a text file. How does it tell if it is the end of the line,...
8
by: siliconwafer | last post by:
Hi All, If I open a binary file in text mode and use text functions to read it then will I be reading numbers as characters or actual values? What if I open a text file and read it using binary...
6
by: R.A. | last post by:
Hi Is there some support for this file conversion in c#? Thanks
4
by: Ram | last post by:
Dear All, Good Day I am trying to convert a file which is generated on AS400 with codepage 00420 (arabic & English data combination) with no success. But using the same code( and changing 20420...
9
by: jeff M via .NET 247 | last post by:
I'm still having problems reading EBCDIC files. Currently itlooks like the lower range (0 to 127) is working. I have triedthe following code pages 20284, 20924, 1140, 37, 500 and 20127.By working I...
12
by: Adam J. Schaff | last post by:
I am writing a quick program to edit a binary file that contains file paths (amongst other things). If I look at the files in notepad, they look like: ...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.