VB - Wie lese ich und eine binäre Datei schreiben?
-
11-09-2019 - |
Frage
Wie kann ich aus einem beliebigen Datei eine rohe Byte-Array lesen ...
Dim bytes() as Byte
.. und schreibt dann den Byte-Array zurück in eine neue Datei?
Ich brauche es als Byte-Array einige Verarbeitung in zwischen zu tun.
Ich bin derzeit mit:
Zum Lesen
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()
Zum Schreiben
Dim fs As System.IO.FileStream
fs = New System.IO.FileStream(outpath, System.IO.FileMode.Create)
fs.Write(bytes, 0, bytes.Length)
fs.Close()
Lösung
Dim data() as Byte = File.ReadAllBytes(path1)
File.WriteAllBytes(path2, data)
Andere Tipps
System.IO.File.ReadAllBytes("myfile.txt")
Versuchen Sie folgendes: -
Dim bytes() as Byte
bytes = File.ReadAllBytes(fileName)
'' # Do stuff to the array
File.WriteAllBytes(otherFileName, bytes)
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow