将字节写入文件vb.net

时间:2015-07-06 13:17:17

标签: vb.net

为什么这段代码不起作用? :(想要从二进制文件中读取,然后将字节加载到bitarray,然后对位数组执行更改,然后将更改复制到字节数组,然后使用字节数组将更改写入文件。我将在中提供注释代码。

Private Sub Button5_Click(sender As Object, e As EventArgs) Handles Button5.Click

    'Want to read from the binary file
    Dim array() As Byte = File.ReadAllBytes("E:\binfile.bin")

    'to create the bit array   
    Dim ba1 As BitArray = New BitArray(8)

    ba1 = New BitArray(array)

    'want to set 1st bit to false (ie:0)
    ba1.Set(0, False)

    'want to set the changes made to bit array to binary array
    array.SetValue(ba1(0), 0)

    'want to save the binary file using binarywriter
    File.WriteAllBytes("E:\binfile.bin", array)
End Sub

0 个答案:

没有答案