Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / New Users / April 2005

Tip: Looking for answers? Try searching our database.

Arbitrary Streamwriter.

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Arne - 11 Apr 2005 19:52 GMT
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();
Cowboy (Gregory A. Beamer) - MVP - 11 Apr 2005 20:59 GMT
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

Jon Shemitz - 11 Apr 2005 22:14 GMT
> 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

Jon Skeet [C# MVP] - 11 Apr 2005 22:23 GMT
> 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


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.