473,698 Members | 2,090 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.t xt" // file that is in EBCDIC
// Create the reader for data.
FileStream fs = new FileStream(FILE _NAME, FileMode.Open,F ileAccess.ReadW rite);
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 "MemoryStre am" and "BinaryRead er" 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 6533
On Jun 20, 2:54 pm, j.a. harriman
<jeffrey_no_spa m_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.GetEnc oding("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
"GetEncodin g" 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_spa m_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.co m

"j.a. harriman" <je************ *******@nospam. nospamwrote in message
news:65******** *************** ***********@mic rosoft.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.GetEnc oding("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
"GetEncodin g" 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_sp am_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.GetEnc oding("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
"GetEncodin g" 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.c s 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.co m>
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
3201
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 indeed also true for our language of choice, Python. Its file type allows some extraordinary convenient access like: for line in open("blah"): handle_line(line)
6
23599
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
1067
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. Packed/Zoned/Binary/Char) and I know how to use the ascii/hex values of the ebcdic characters to extract the correct ascii text. The current application that I am using is just not fast enough. My thoughts are to rewrite the entire conversion application in C/C++/C#....
14
7417
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, is there such thing call EOL like the EOF? -- Posted via http://dbforums.com
8
1785
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 read functions. -Siliconwafer
6
925
by: R.A. | last post by:
Hi Is there some support for this file conversion in c#? Thanks
4
7120
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 to 708) I am able to convert a file from codepage ASMO 708 to windows based file and it is perfect. The following is the code I tried. i used 20420 codepage which is the nearest match for 00420. but no luck. //Open file for reading and set...
9
6757
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 get the correct answer by taking the decimal valueand using that as an index to an array that will map to thecorrect EBCDIC value in hex. By larger values, an example would be "AA" in EBCDIC hex wouldgive me the value of 63 in decimal (ASCII) when...
12
5886
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: <gibberish>file//g:\pathtofile1<gibberish>file//g:\pathtofile2<gibberish> etc. I want to remove the "g:\" from the file paths. I wrote a console app that successfully reads the file and writes a duplicate of it, but fails for some reason to do the "replacing" of the "g:\". The code...
0
8598
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9152
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9016
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8887
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8856
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7709
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5858
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4613
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2321
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.