Вопрос

Как прочитать массив необработанных байтов из любого файла...

 Dim bytes() as Byte

...а затем записать этот массив байтов обратно в новый файл?

Мне это нужно как массив байтов для промежуточной обработки.


В настоящее время я использую:

Читать

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

Написать

Dim fs As System.IO.FileStream
fs = New System.IO.FileStream(outpath, System.IO.FileMode.Create)
fs.Write(bytes, 0, bytes.Length)
fs.Close()
Это было полезно?

Решение

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

Другие советы

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

Попробуй это:-

Dim bytes() as Byte
bytes = File.ReadAllBytes(fileName)
'' # Do stuff to the array
File.WriteAllBytes(otherFileName, bytes)
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top