Array Byte To FileStream (to blocks)

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()
 
A

Armin Zingler

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top