PC Review


Reply
Thread Tools Rate Thread

BinaryWriter is not binary enough

 
 
=?Utf-8?B?QXJuZQ==?=
Guest
Posts: n/a
 
      11th Apr 2005
The Binarywriter appends an extra carriage return at the end. Is there a way
to supress that?

string file = @"c:\temp\binary.txt";
FileStream fs= new FileStream(file,
FileMode.Create, FileAccess.Write, FileShare.None);
BinaryWriter bw = new BinaryWriter(fs);
bw.Write("BINARY PLEASE");
bw.Flush();
bw.Close();
 
Reply With Quote
 
 
 
 
=?Utf-8?B?Q293Ym95IChHcmVnb3J5IEEuIEJlYW1lcikgLSBN
Guest
Posts: n/a
 
      11th Apr 2005
I have never used a binary writer in this fashion, but I do not remember
having a problem when the message I was sending was converted to binary
before sending to the stream. You might want to test conversion first rather
than relying on the stream/writer to convert for you.


---

Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

***************************
Think Outside the Box!
***************************

"Arne" wrote:

> The Binarywriter appends an extra carriage return at the end. Is there a way
> to supress that?
>
> string file = @"c:\temp\binary.txt";
> FileStream fs= new FileStream(file,
> FileMode.Create, FileAccess.Write, FileShare.None);
> BinaryWriter bw = new BinaryWriter(fs);
> bw.Write("BINARY PLEASE");
> bw.Flush();
> bw.Close();

 
Reply With Quote
 
Jon Skeet [C# MVP]
Guest
Posts: n/a
 
      11th Apr 2005
Arne <(E-Mail Removed)> wrote:
> The Binarywriter appends an extra carriage return at the end. Is there a way
> to supress that?
>
> string file = @"c:\temp\binary.txt";
> FileStream fs= new FileStream(file,
> FileMode.Create, FileAccess.Write, FileShare.None);
> BinaryWriter bw = new BinaryWriter(fs);
> bw.Write("BINARY PLEASE");
> bw.Flush();
> bw.Close();


It's not putting a carriage return at the end, it's putting a byte 13
at the *start* of the stream, just as described by
BinaryWriter.Write(string) - it's the length prefix for the string
data, basically.

Here's a dump of the file written by the above code:

00000000 0D 42 49 4E 41 52 59 20 50 4C 45 41 53 45 .BINARY PLEASE

--
Jon Skeet - <(E-Mail Removed)>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
BinaryWriter not converting strings to binary testrasbath@gmail.com Microsoft C# .NET 2 21st Mar 2007 01:17 PM
How to change binary data buffer read from a binary file to string format Anderson Microsoft VC .NET 1 21st Jul 2006 11:35 AM
Solver returns non binary answer in binary constrained cells =?Utf-8?B?TmF2eSBTdHVkZW50?= Microsoft Excel Worksheet Functions 6 1st Sep 2005 03:11 PM
Writing binary array directly to binarywriter dsmith@iftd.org Microsoft C# .NET 1 16th Dec 2004 10:24 PM
BinaryWriter.Seek() vs BinaryWriter.BaseStream.Seek() Daniel Goldman Microsoft Dot NET Framework 6 30th Aug 2003 08:26 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 06:47 AM.