6

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

 Dim bytes() as Byte

..然后将该字节数组写回一个新文件?

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


我目前正在使用:

读书

 Dim fInfo As New FileInfo(dataPath)
 Dim numBytes As Long = fInfo.Length
 Dim fs As 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()
4

3 回答 3

16
Dim data() as Byte = File.ReadAllBytes(path1)
File.WriteAllBytes(path2, data)
于 2009-09-20T08:11:49.527 回答
5
System.IO.File.ReadAllBytes("myfile.txt")
于 2009-09-20T08:11:24.770 回答
3

尝试这个:-

Dim bytes() as Byte
bytes = File.ReadAllBytes(fileName)
'' # Do stuff to the array
File.WriteAllBytes(otherFileName, bytes)
于 2009-09-20T08:12:17.647 回答