about binaryreader

G

Guest

Hello MVPs:

I am not sure when to use binaryreader in .net is best?
In fact ,I am coding a program which converts data in text files
into DB. but i have to use fixed length to read data in file(old format).
Here fixed length means the count of bytes read not the count of chars read.
because there are 2-byte chars in the data file. What about to use
binaryreader to read a text file to solve this problem.
If i use streamreader,how to accomplish it?

thanks in advance.
 
J

Jon Skeet [C# MVP]

gladiator said:
Hello MVPs:

And anyone else who care to responds, I hope.
I am not sure when to use binaryreader in .net is best?

When you're reading a *binary* file containing primitives encoded in
the way that BinaryReader understands, IME.
In fact ,I am coding a program which converts data in text files
into DB. but i have to use fixed length to read data in file(old format).
Here fixed length means the count of bytes read not the count of chars read.
because there are 2-byte chars in the data file. What about to use
binaryreader to read a text file to solve this problem.
If i use streamreader,how to accomplish it?

StreamReader sounds like the way to go. Are there line breaks between
records, by any chance? If so, just use ReadLine to read a line at a
time, and break up the string with Substring.

It's *slightly* more tricky otherwise, because you'll need to read into
a buffer of the right size repeatedly until the buffer is full, then
process that record. Far from difficult though.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top