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

BinaryWriter problem

Hello all,
This is my first c# program. And I seem to have a problem. Here is the
code:

FileStream myStream = new FileStream("d:\\test.txt",
FileMode.Create, FileAccess.Write);

BinaryWriter writer = new BinaryWriter(myStream);

writer.Write("ntestestse");
writer.Close();

In my text file I get a line feed 0x0a as the first char and then the
string "ntestestse" (including the n). I have realised that if i
change the string to test then I get a 0x09 (tab) as the first char in
the file. so it seems to be related to the first char of my string.
Any ideas???

thanks
Peyman Zehtab-Fard
Nov 15 '05 #1
3 3796
Peyman,
BinaryWriter writes strings as a counted (length prefixed) string. It writes
one or more bytes of how many characters are in the string followed by the
string.

For details see the BinaryWriter.Write(String) method &
BinaryReader.ReadString methods:

http://msdn.microsoft.com/library/de...iteTopic13.asp

http://msdn.microsoft.com/library/de...tringTopic.asp

Hope this helps
Jay

"Peyman" <pe*****@netscape.net> wrote in message
news:69**************************@posting.google.c om...
Hello all,
This is my first c# program. And I seem to have a problem. Here is the
code:

FileStream myStream = new FileStream("d:\\test.txt",
FileMode.Create, FileAccess.Write);

BinaryWriter writer = new BinaryWriter(myStream);

writer.Write("ntestestse");
writer.Close();

In my text file I get a line feed 0x0a as the first char and then the
string "ntestestse" (including the n). I have realised that if i
change the string to test then I get a 0x09 (tab) as the first char in
the file. so it seems to be related to the first char of my string.
Any ideas???

thanks
Peyman Zehtab-Fard

Nov 15 '05 #2
Peyman,
BinaryWriter writes strings as a counted (length prefixed) string. It writes
one or more bytes of how many characters are in the string followed by the
string.

For details see the BinaryWriter.Write(String) method &
BinaryReader.ReadString methods:

http://msdn.microsoft.com/library/de...iteTopic13.asp

http://msdn.microsoft.com/library/de...tringTopic.asp

Hope this helps
Jay

"Peyman" <pe*****@netscape.net> wrote in message
news:69**************************@posting.google.c om...
Hello all,
This is my first c# program. And I seem to have a problem. Here is the
code:

FileStream myStream = new FileStream("d:\\test.txt",
FileMode.Create, FileAccess.Write);

BinaryWriter writer = new BinaryWriter(myStream);

writer.Write("ntestestse");
writer.Close();

In my text file I get a line feed 0x0a as the first char and then the
string "ntestestse" (including the n). I have realised that if i
change the string to test then I get a 0x09 (tab) as the first char in
the file. so it seems to be related to the first char of my string.
Any ideas???

thanks
Peyman Zehtab-Fard

Nov 15 '05 #3
Thanks,
I should have seen that. I am using StreamWriter now and all is working
fine.

Regards
Peyman Zehtab-Fard

"Jay B. Harlow [MVP - Outlook]" <Ja********@email.msn.com> wrote in message
news:OW**************@TK2MSFTNGP12.phx.gbl...
Peyman,
BinaryWriter writes strings as a counted (length prefixed) string. It writes one or more bytes of how many characters are in the string followed by the
string.

For details see the BinaryWriter.Write(String) method &
BinaryReader.ReadString methods:

http://msdn.microsoft.com/library/de...iteTopic13.asp
http://msdn.microsoft.com/library/de...tringTopic.asp
Hope this helps
Jay

"Peyman" <pe*****@netscape.net> wrote in message
news:69**************************@posting.google.c om...
Hello all,
This is my first c# program. And I seem to have a problem. Here is the
code:

FileStream myStream = new FileStream("d:\\test.txt",
FileMode.Create, FileAccess.Write);

BinaryWriter writer = new BinaryWriter(myStream);

writer.Write("ntestestse");
writer.Close();

In my text file I get a line feed 0x0a as the first char and then the
string "ntestestse" (including the n). I have realised that if i
change the string to test then I get a 0x09 (tab) as the first char in
the file. so it seems to be related to the first char of my string.
Any ideas???

thanks
Peyman Zehtab-Fard


Nov 15 '05 #4

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

Similar topics

3
by: Mark Miller | last post by:
I have a char array and when I write it to a file using BinaryWriter the position of the pointer is the size of the array + 1. For example: writing char leaves the pointer at position 26 after...
6
by: ThunderMusic | last post by:
Hi, In my app, I open a file using a FileStream then pass it to a BinaryWriter. I then use the BinaryWriter instance to write to my file. But a problem arose : The file never gets bigger than 1kb....
17
by: Filip Strugar | last post by:
Considering that the BinaryWriter/BinaryReader object closes the underlaying stream upon being gc collected, is the following code correct, and if it is what is the reason preventing BinaryWriter...
1
by: Claire | last post by:
I'm writing from a serial port into a MemoryStream via a BinaryWriter in my protocol object. After I've filled the memorystream, which is approx 200KB in size, I then pass it up to my datahandler...
1
by: Barguast | last post by:
Is it necessary to call the close method for every BinaryWriter that I create? Or is it just a way to close the underlying stream? For example is it OK to do the following: private void...
5
by: Boris | last post by:
// Example BinaryWriter bw = new BinaryWriter(new FileStream("c:\Test.bin",FileMode.Append)); BinaryWriter.Write writes data to the stream. However, it doesn't automatically flush data any...
3
by: Eugene | last post by:
I'm trying to write a class which uses BinaryWriter as its base but allows for queuing of write requests Public Class QueuedBinaryWriter Inherits BinaryWriter I override all the Write methods...
3
by: =?Utf-8?B?ZnVuZG9vX2ty?= | last post by:
Check the following code ///Buffer to store the data byte data = new byte; ///Create a memory stream from the buffer MemoryStream memStream = new MemoryStream(data); ///Binary writer...
7
by: Peter Morris | last post by:
Can I use a BinaryWriter without it closing the underlying stream? I want to save information to a MemoryStream using a BinaryWriter but I want to dispose of the BinaryWriter and keep 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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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:
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
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
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,...

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.