Disapperaring bytes

  • Thread starter Thread starter H.J. Simpson
  • Start date Start date
H

H.J. Simpson

Hello,
i have a serious problem with some data. It looks like all Stream
objects simply lose bytes when reading from a file.... in particular all of
those chars that have an ascii code >127 i.e. (for me, i am italian...)
"è","°","é" etc etc.

Any idea??
 
here's some code of mine: notice that System.Text.Encoding.* means that i
tryed every possible combination of values, including... leaving it blank

the file "ordini.vb" i am trying to duplicate is a evb "exe", a binary
file....

my needs are to transfer it between a server and the pda, so a simple
"filecopy" is not the answer for my needs...
btw, i was looking for a method to retrieve the file length, but it seems
impossible without using a stream....

Dim fsw As New FileStream("\ordini2.vb", FileMode.Truncate)
Dim fsr As New FileStream("\programmi\ordini\ordini.vb",
FileMode.OpenOrCreate)
Dim br As New BinaryReader(fsr, System.Text.Encoding.*)
Dim bw As New BinaryWriter(fsw, System.Text.Encoding.*)
bw.Write(br.ReadBytes(br.BaseStream.Length))
br.Close()
bw.Close()

hope you can help!!
 
eheheheheheh

certo che sono italiano

anche tu, avventuroso del compact framework??

"nino" <[email protected]> ha scritto nel messaggio
simpatico
(dal nome avevo intuito ke fosse 1 italiano...)
 
H.J. Simpson said:
Hello,
i have a serious problem with some data. It looks like all Stream
objects simply lose bytes when reading from a file.... in particular all of
those chars that have an ascii code >127 i.e. (for me, i am italian...)
"è","°","é" etc etc.

Any idea??

If you use a converter for Byte<->String, then imho you have to use
sBuffer += System.Text.Encoding.Default.GetString(yBuffer, 0,
lReturnedBuffer)

If you use e.g. .ASCII. instead of .Default. , then all characters
having a value > 127 are lost. This happens also with SOME characters
when using .UTF8.

DEFAULT selects the converter for the current language and seems to make
no conversion for special characters...


Benjamin Lukner
 
Instead of struggling with the encoding (which is IMO the root of your
problem), why don't you forget about BinaryReader at all?

Dim fsw As New FileStream("\ordini2.vb", FileMode.Truncate)
Dim fsr As New FileStream("\programmi\ordini\ordini.vb",
FileMode.OpenOrCreate)
Dim buffer as new Byte(fsr.Length)
fsr.Read(buffer, 0, fsr.Length)
fsw.Write(buffer, 0, fsr.Length)


If your files are expected to be large, the above should be rewritten as a
loop, copying the file in chunks
 
Thank you very much for your help...
Dim buffer as new Byte(fsr.Length)
fsr.Read(buffer, 0, fsr.Length)
fsw.Write(buffer, 0, fsr.Length)

this was my solution, too
If your files are expected to be large, the above should be rewritten as a
loop, copying the file in chunks

I will... my files will be exectly 512 k each (uncompressed)


i am very happy to know that in case of problems i can find such a qualified
help here!!!

thank you again, Paolo aka Homer (guess why....:)
 
Back
Top