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

C# App: Getting extra bytes using BinaryWriter

I'm trying to export data to a binary file. I have imported the data from a binary file using BinaryReader and everything works as I would have expected. The data after importing is a variety of mainly numerical types. I export it using BinaryWriter exactly the same way but get a much larger binary file. My research tells me that the Write method in BinaryWriter prefixes the bytes with the length.

How can I avoid this? I'm quite new to this so if you can idiot proof any answers, that would be great!

Here is an example of the code I have written to output the data:

System.IO.FileStream FS = new System.IO.FileStream(FileName, System.IO.FileMode.Create);
System.IO.BinaryWriter BW = new System.IO.BinaryWriter(FS);

for (int ii = 0; ii < 32; ii++)
{
BW.Write(pMM.Header.bB1_32[ii]);
}

Do I perhaps need to convert the data into bytes and then write it using the FileStream? If so, how do I do this?
Feb 3 '08 #1
1 2005
Plater
7,872 Expert 4TB
Do I perhaps need to convert the data into bytes and then write it using the FileStream? If so, how do I do this?
I would say that yes that should work. FileStream will write a byte[] so all you have to do is get your data in byte form.

If you read in the entire file using BinaryReader, then writing out the entire file with BinaryWriter should have produced the same file? (I will do a bit of testing when I have time) You aren't doing any up-converting are you? like an int16 to an int32 or int64?
Feb 4 '08 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: James | last post by:
We are writing a web based application which primarily will serve information to run an ivr. Based on our current IVR getting 1000000 hits a week, this is going to be heavy duty. We have very...
9
by: John | last post by:
Hi, I need to write out bits that I receive from another process. These are boolean values. I need there to be 8 bits in every byte. I know I could write these bits out as char's using one bit...
12
by: bj7lewis | last post by:
I am working on a project I want to add a few files as resource to access(copy them to FS and use) at runtime. So far in VS.NET IDE, I Add Files to the project and set its Build Action to...
3
by: Glenn Owens | last post by:
I've just deployed an asp.net 1.1 web app to the remote server (Win 2000). All of the pages work fine with one exception. Part of this app's purpose is to upload and download files to/from a...
0
by: iwdu15 | last post by:
hi, im creating an instant messenger using TCP sockets, and everythings been fine until now. i want to be able to send rich text, but im hitting a wall here. what i want to do is send the font...
5
by: philip | last post by:
Here is some lines of code than I wrote. You can copy/paste theis code as code of form1 in a new project. My problem is this one : I try to write in a file a serie of bytes. BUT some bytes...
12
by: AK_TIREDOFSPAM | last post by:
I need to store a uint in an array of bytes. Doing it old fashioned style works: byte b=new byte; ulong ul = 1; for(int j=0; j<8; j++) { --- obviously I could (and did) optimize the code...
8
by: paraidy | last post by:
Hi all, as from object i need to read all byte from a file example c: \myphoto.jpg and recreate the file with another name to another directory c:\photo\recreatedphoto.jpg can someone write a...
1
by: Paul J. Lucas | last post by:
I have code that builds a DOM using the Java org.w3c.dom API and it adds an extra attribute to one of the elements that I don't want. Not only that, the value it adds is wrong. The code to...
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
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...
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
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
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,...
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.