The streamwriter appends an extra carriage return at the end. Is there a way
to supress that?
file = @"c:\temp\text.txt";
fs = new FileStream(file,
FileMode.Create, FileAccess.Write, FileShare.None);
StreamWriter sw = new StreamWriter(fs);
sw.Write("BINARY PLEASE");
sw.Flush();
sw.Close();
As I understand, this is normal. Without the carriage return at the end, you
do not end up with the null that indicates EOS.
---
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA
***************************
Think Outside the Box!
***************************
> The streamwriter appends an extra carriage return at the end. Is there a way
> to supress that?
[quoted text clipped - 6 lines]
> sw.Flush();
> sw.Close();
Arne - 11 Apr 2005 21:58 GMT
Cowboy,
It might be normal, but it doesn't fit my business requirement. I need to
create a file without a carriage return that I can FTP to a mainframe, where
carriage returns are not welcome.
> As I understand, this is normal. Without the carriage return at the end, you
> do not end up with the null that indicates EOS.
[quoted text clipped - 18 lines]
> > sw.Flush();
> > sw.Close();
Jon Skeet [C# MVP] - 11 Apr 2005 22:24 GMT
Cowboy (Gregory A. Beamer) - MVP <NoSpamMgbworld@comcast.netNoSpamM>
wrote:
> As I understand, this is normal.
No it's not - and it doesn't actually happen. (Look at my other reply
to this thread.)
> Without the carriage return at the end, you
> do not end up with the null that indicates EOS.
There *is* no null that indicates end of stream. Some APIs may return 0
or some other special value to indicate the end of the stream, but it's
not actually present as a logical part of the file. The file itself (as
created by the OP's code) is 13 bytes long - one byte per character (as
all the characters are ASCII, and StreamWriter uses UTF-8 by default).

Signature
Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
> The streamwriter appends an extra carriage return at the end. Is there a way
> to supress that?
[quoted text clipped - 6 lines]
> sw.Flush();
> sw.Close();
Does the StreamWriter's NewLine property do what you want?

Signature
www.midnightbeach.com
> The streamwriter appends an extra carriage return at the end. Is there a way
> to supress that?
[quoted text clipped - 6 lines]
> sw.Flush();
> sw.Close();
The above code doesn't write a carriage return. Try running the
following program (containing your code, modified for my directory
structure):
using System;
using System.IO;
class Test
{
static void Main()
{
string file = @"c:\test\text.txt";
FileStream fs = new FileStream(file,
FileMode.Create, FileAccess.Write,
FileShare.None);
StreamWriter sw = new StreamWriter(fs);
sw.Write("BINARY PLEASE");
sw.Flush();
sw.Close();
}
}
The file length afterwards is 13 bytes, which doesn't leave any room
for carriage returns, if you count the characters in the string...

Signature
Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Arne - 12 Apr 2005 13:17 GMT
Jon,
Maybe it is my stupid editor that adds another carriage return. What would
be your favorite tool to display all the bytes?
> > The streamwriter appends an extra carriage return at the end. Is there a way
> > to supress that?
[quoted text clipped - 31 lines]
> The file length afterwards is 13 bytes, which doesn't leave any room
> for carriage returns, if you count the characters in the string...
Jon Skeet [C# MVP] - 12 Apr 2005 17:33 GMT
> Maybe it is my stupid editor that adds another carriage return. What would
> be your favorite tool to display all the bytes?
Either dump (can't remember where I got mine) or frhed (a binary file
editor). Alternatively you could open it in Visual Studio in binary
mode.

Signature
Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too