Domanda

Come faccio a leggere un array di byte grezzo da qualsiasi file ...

 Dim bytes() as Byte

.. e poi scrivere che matrice di byte di nuovo in un nuovo file?

mi serve come un array di byte per fare un po 'di elaborazione in mezzo.


Attualmente sto usando:

Per leggere

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

Per scrivere

Dim fs As System.IO.FileStream
fs = New System.IO.FileStream(outpath, System.IO.FileMode.Create)
fs.Write(bytes, 0, bytes.Length)
fs.Close()
È stato utile?

Soluzione

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

Altri suggerimenti

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

Prova questo: -

Dim bytes() as Byte
bytes = File.ReadAllBytes(fileName)
'' # Do stuff to the array
File.WriteAllBytes(otherFileName, bytes)
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top