Hello,
I read a file via Stream Reader which is associated with web response
from linux server and using Stream Writer to write to a text file.
I read a text file and for some reason I read an extra empty line which
is not part of the file.Why can it happen? Maybe it has something to do
with Linux via Windows ?
I did : streamReader.NewLine ="\n" and it didn't help.
Why is that?
Thanks!
not_a_commie - 27 Feb 2008 17:14 GMT
> I did : streamReader.NewLine ="\n" and it didn't help.
Try "\r\n" or just "\r". Does Stream Reader have a text/binary mode
toggle? If you read the file with File.ReadAllText variants do you see
the same problem?
Rene - 27 Feb 2008 19:18 GMT
Is my understanding that operating systems like Linux will used LF (line
feed) to represent a new line where operating systems such as Microsoft
Windows use CR+LF (Carriage return + Line Feed) to represent a new line.
Could this be the cause of your problems?
> Hello,
>
[quoted text clipped - 8 lines]
>
> *** Sent via Developersdex http://www.developersdex.com ***
Arne Vajhøj - 27 Feb 2008 23:22 GMT
> I read a file via Stream Reader which is associated with web response
> from linux server and using Stream Writer to write to a text file.
> I read a text file and for some reason I read an extra empty line which
> is not part of the file.Why can it happen? Maybe it has something to do
> with Linux via Windows ?
My guess is that the web server returned:
line 1<CR><LF>
line 2<CR><LF>
...
line n<CR><LF>
which turns out to be:
line 1
line 2
...
line n
(blank line)
And I would not really consider it a problem.
Arne
christery@gmail.com - 28 Feb 2008 02:51 GMT
> > I read a file via Stream Reader which is associated with web response
> > from linux server and using Stream Writer to write to a text file.
[quoted text clipped - 20 lines]
>
> Arne
Or reading between the lines...
line 1
(blank line)
line 2
(blank line)
...
(blank line)
line n
(blank line)
Go for the CR/LF translation problem, got some of the same from VMS,
but lacking breaks, so the text is just one line, but
looooooooooong...
//CY
csharpula csharp - 28 Feb 2008 09:41 GMT
Hello again,
My problem is te empty line in the end of te stream. I tried all the
options of "/n","/r","/n/r" and nothing helps.
Is there any thing I can mplement (except for adding if for ignoring) in
order not to read this empty line in the end?
Thanks a lot!
Jon Skeet [C# MVP] - 28 Feb 2008 09:49 GMT
> My problem is te empty line in the end of te stream. I tried all the
> options of "/n","/r","/n/r" and nothing helps.
> Is there any thing I can mplement (except for adding if for ignoring) in
> order not to read this empty line in the end?
How sure are you that the empty line doesn't exist in the original
file? Many files *do* end with an empty line. What's the binary data at
the end of the file?

Signature
Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
World class .NET training in the UK: http://iterativetraining.co.uk