VB-如何读写二进制文件? [英] VB - How do I read and write a binary file?

查看:581
本文介绍了VB-如何读写二进制文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

How do I read a raw byte array from any file...

 Dim bytes() as Byte

..然后将该字节数组写回到新文件中?

..and then write that byte array back into a new file?

我需要它作为字节数组在两者之间进行一些处理.

I need it as a byte array to do some processing in between.

我当前正在使用:

阅读

 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-如何读写二进制文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆