Pergunta

Como faço para ler um array de bytes bruto de qualquer arquivo ...

 Dim bytes() as Byte

.. e então escrever isso de volta matriz de bytes em um novo arquivo?

Eu preciso-lo como uma matriz de bytes para fazer algum processamento no meio.


Eu estou usando atualmente:

Para ler

 Dim fInfo As New FileInfo(dataPath)
 Dim numBytes As Long = fInfo.Length
 Dim fsAs New FileStream(dataPath, FileMode.Open, FileAccess.Read)
 Dim br As New BinaryReader(fs)
 Dim bytes As Byte() = br.ReadBytes(CInt(numBytes))
 br.Close()
 fs.Close()

Para escrever

Dim fs As System.IO.FileStream
fs = New System.IO.FileStream(outpath, System.IO.FileMode.Create)
fs.Write(bytes, 0, bytes.Length)
fs.Close()
Foi útil?

Solução

Dim data() as Byte = File.ReadAllBytes(path1)
File.WriteAllBytes(path2, data)

Outras dicas

System.IO.File.ReadAllBytes("myfile.txt")

Tente isto: -

Dim bytes() as Byte
bytes = File.ReadAllBytes(fileName)
'' # Do stuff to the array
File.WriteAllBytes(otherFileName, bytes)
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top