Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Stream does not return the same amount of bytes
Message
De
13/02/2013 11:40:18
 
 
À
13/02/2013 11:18:34
Information générale
Forum:
ASP.NET
Catégorie:
Autre
Versions des environnements
Environment:
VB 9.0
OS:
Windows 7
Network:
Windows 2003 Server
Database:
MS SQL Server
Application:
Web
Divers
Thread ID:
01565895
Message ID:
01565900
Vues:
55
When you say "on disk which says that it has 200,000 bytes", do you mean in Windows Explorer? That's rarely the exact file size because it reports file space allocated (block size).

>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?
Craig Berntson
MCSD, Microsoft .Net MVP, Grape City Community Influencer
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform