473,402 Members | 2,055 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,402 software developers and data experts.

about binaryreader

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.

Aug 25 '05 #1
1 1568
gladiator <gl*******@discussions.microsoft.com> wrote:
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.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Aug 25 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: C# Learner | last post by:
Some time ago, I remember reading a discussion about the strengths and weaknesses of exception handling. One of the weaknesses that was put forward was that exception handling is inefficient (in...
6
by: Question with BinaryReader | last post by:
I use BinaryReader to read my binary dafa files, when i call ReadBytes, why it always return more 4 bytes. The following is my code. FileStream fs = new FileStream(file, FileMode.OpenOrCreate,...
1
by: gladiator | last post by:
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...
3
by: =?Utf-8?B?VmljdG9y?= | last post by:
Hi, Could you tell me can I keep the MemoryStream open and "close" the BinaryReader? As the MemoryStream is used for buffering the TCP data and BinaryReader is only used to read the...
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: 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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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...
0
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,...
0
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...
0
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...
0
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...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...

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.