gpt4 book ai didi

vb.net - VB - 如何读取和写入二进制文件?

转载 作者:行者123 更新时间:2023-12-04 13:06:33 37 4
gpt4 key购买 nike

如何从任何文件中读取原始字节数组...

 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)

关于vb.net - VB - 如何读取和写入二进制文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1450568/

37 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com