Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vb.net/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Vb.net 检查文件中的特定字节是否在vb中设置为特定值_Vb.net_Binary_Byte_Seek - Fatal编程技术网

Vb.net 检查文件中的特定字节是否在vb中设置为特定值

Vb.net 检查文件中的特定字节是否在vb中设置为特定值,vb.net,binary,byte,seek,Vb.net,Binary,Byte,Seek,我希望能够使是这样,当我的程序加载它检查,看看是否在文件中的字节设置为特定的东西。如果设置为某个字节,则执行代码 所以我想让它转到一个特定的字节,检查它是否是一个特定的字节,如果是那个特定的字节,那么执行代码,如果是其他的,那么执行其他的代码 我试过这个: Dim bytes As Byte() = New Byte(writeStream.Length) {} Dim ByteResult As Integer = writeStream.Read(bytes, 30, 1)

我希望能够使是这样,当我的程序加载它检查,看看是否在文件中的字节设置为特定的东西。如果设置为某个字节,则执行代码

所以我想让它转到一个特定的字节,检查它是否是一个特定的字节,如果是那个特定的字节,那么执行代码,如果是其他的,那么执行其他的代码

我试过这个:

    Dim bytes As Byte() = New Byte(writeStream.Length) {}
    Dim ByteResult As Integer = writeStream.Read(bytes, 30, 1)

    MsgBox(ByteResult)
        Dim dataArray(60) As Byte

    If dataArray(30) <> writeStream.ReadByte() - 0 Then
        MsgBox("The bytes have been checked.")
    End If
但它不起作用,因为出于某种原因,它总是返回1

我也试过:

    Dim bytes As Byte() = New Byte(writeStream.Length) {}
    Dim ByteResult As Integer = writeStream.Read(bytes, 30, 1)

    MsgBox(ByteResult)
        Dim dataArray(60) As Byte

    If dataArray(30) <> writeStream.ReadByte() - 0 Then
        MsgBox("The bytes have been checked.")
    End If
Dim数据阵列(60)作为字节
如果dataArray(30)writeStream.ReadByte()-0,则
MsgBox(“已检查字节”)
如果结束
但这似乎也不起作用,因为它从未为我打开过信息框

例如,我希望它寻找偏移量30,然后检查字节是否为00,然后我希望它执行代码1,否则,如果是01,我希望它执行代码2


谢谢。

我发现以下代码有效:

        fLocation = ("file.txt")

        Dim writeStream As New FileStream(fLocation, FileMode.Open)
        Dim writeBinary As New BinaryWriter(writeStream)

        writeStream.Seek(30, SeekOrigin.Begin)
        Dim ByteResult = writeStream.ReadByte()

        MsgBox(ByteResult)
你也可以这样做

    Dim FileStream1 As New IO.FileStream("File.txt", IO.FileMode.Open)

    FileStream1.Position = 30
    MsgBox(FileStream1.ReadByte)

    FileStream1.Close()
    FileStream1.Dispose()

因为BinaryWriter没有ReadByte方法,所以我看不出它是如何工作的。也许您打算使用BinaryReader?我不是从BinaryWriter而是从Filestream调用ReadByte方法。我已经编写了writeStream.ReadByte,但我认为您将其读为writeBinary.ReadByte。这也可以完成工作,是的。但我认为总体而言,地雷更容易理解。但是你的很好,很短。