Array Byte To FileStream (to blocks)

  • Thread starter Thread starter Tony
  • Start date Start date
T

Tony

Hello,

I a byte array and i put to remote class (to blocks)

I read byte array from a file :
dim fs as FileStream = File.Open(filename, FileMode.Open);
dim data() as byte = new byte(fs.Length){}
fs.Read(data, 0, data.Length)
fs.Close()

How write to blocks a array to File Stream?

I have Write this code byt not it works :

Dim i As Integer
Dim currentChunk As Integer=0
Dim buffsize As Integer = 4096
Dim fs As FileStream
Dim Data(buffsize) As Byte

fs = New FileStream("C:\fileDestination", FileMode.CreateNew)

Dim bw As BinaryWriter = New BinaryWriter(fs)

For i = 0 To arrayByte.Length / buffsize
currentChunk = (i * buffsize)
If currentChunk + buffsize > arrayByte.Length Then
buffsize = arrayByte.Length - currentChunk
End If
buffer.BlockCopy(arrayByte, currentChunk, Data, 0, buffsize)
bw.Write(Data)
Next

bw.Close()
 
Tony said:
Hello,

I a byte array and i put to remote class (to blocks)

I read byte array from a file :
dim fs as FileStream = File.Open(filename, FileMode.Open);
dim data() as byte = new byte(fs.Length){}
fs.Read(data, 0, data.Length)
fs.Close()

You are reading 0 bytes because data.length = 0.
How write to blocks a array to File Stream?

I have Write this code byt not it works :

Dim i As Integer
Dim currentChunk As Integer=0
Dim buffsize As Integer = 4096
Dim fs As FileStream
Dim Data(buffsize) As Byte

fs = New FileStream("C:\fileDestination", FileMode.CreateNew)

Dim bw As BinaryWriter = New BinaryWriter(fs)

For i = 0 To arrayByte.Length / buffsize


You should enable Option Strict to make you aware of programming problems.

Armin
 
Back
Top