Pregunta

¿Cómo se lee una matriz de bytes primaria de cualquier tipo de archivo ...

 Dim bytes() as Byte

.. y luego escribir ese conjunto de bytes de nuevo en un nuevo archivo?

Lo necesito como una matriz de bytes que hacer algún tipo de procesamiento en el medio.


Actualmente estoy usando:

Para leer

 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 escribir

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

Solución

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

Otros consejos

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

Prueba esto: -

Dim bytes() as Byte
bytes = File.ReadAllBytes(fileName)
'' # Do stuff to the array
File.WriteAllBytes(otherFileName, bytes)
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top