Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Stream does not return the same amount of bytes
Message
From
13/02/2013 11:18:34
 
 
To
All
General information
Forum:
ASP.NET
Category:
Other
Title:
Stream does not return the same amount of bytes
Environment versions
Environment:
VB 9.0
OS:
Windows 7
Network:
Windows 2003 Server
Database:
MS SQL Server
Application:
Web
Miscellaneous
Thread ID:
01565895
Message ID:
01565895
Views:
71
I have a file on disk which says that it has 200,000 bytes. This is from a right click on the file with Properties.

My code is as follow:
 ' If the stream is not set yet
                    If oStreamWriter Is Nothing Then

                        ' If we cannot get the encoding
                        loFileFunction.cFile = cFile
                        If Not loFileFunction.GetEncoding() Then

                        End If

                        oStreamWriter = New StreamWriter(oFileStream, loFileFunction.cEncoding)
                    End If

                    loFile = New IO.StreamReader(cFile)
                    oStreamWriter.Write(loFile.ReadToEnd())
                    loFile.Close()
                    nLength = oStreamWriter.BaseStream.Length
Basically, I call loFileFunction.GetEncoding() to obtain the encoding of the file. It is ANSI. So, oStreamWriter can create the stream with the proper encoding. I verified that. The file is in fact created with ANSI encoding.

Then, I use StreamReader() and make uses of its object ReadToEnd(). Just to be sure of the length I have at this point in the oStreamWriter, I store that into nLength. The value is 188416, which is very far from 200000. Where are the missing 11584 bytes?
Michel Fournier
Level Extreme Inc.
Designer, architect, owner of the Level Extreme Platform
Subscribe to the site at https://www.levelextreme.com/Home/DataEntry?Activator=55&NoStore=303
Subscription benefits https://www.levelextreme.com/Home/ViewPage?Activator=7&ID=52
Next
Reply
Map
View

Click here to load this message in the networking platform