0

ファイル内の特定のバイトをシークして、そのバイトを変更できるようにしたいと考えています。いくつか試してみましたが、何も機能しません。

        Const fileName As String = "Option.mco"

    Using writer As BinaryWriter = New BinaryWriter(File.Open(fileName, FileMode.Create))
        writer.Seek(39, SeekOrigin.Begin)
        writer.Write(1600)
    End Using

このコードを使用してバイト 39 に移動できますが、問題は、このバイトの前のすべてが 00 に変わり、それ以降のすべてが削除されることです。

私もこれを試しました:

     Dim fLocation = ("Option.mco")
    Dim fInfo As New FileInfo(fLocation)
    Dim numBytes As Long = fInfo.Length
    Dim fStream As New FileStream(fLocation, FileMode.Open, FileAccess.Read)
    Dim br As New BinaryReader(fStream)
    Dim data As Byte() = br.ReadBytes(CInt(numBytes))
    Dim fs As New FileStream(fLocation, FileMode.Open, FileAccess.Read)


    ' Show the number of bytes in the array.
    'Label1.Text = Convert.ToString(data.Length)

    'Dim writeStream As FileStream
    'writeStream = New FileStream(fLocation, FileMode.Create)
    'Dim writeBinay As New BinaryWriter(writeStream)

    Dim value As Short = 1600
    Dim value2 As Short = 900
    Dim dataArray(1600) As Byte
    fs.Seek(39, SeekOrigin.Begin)
    fs.Write(1600)
    'writeBinay.Write(value)
    fs.Seek(43, SeekOrigin.Begin)
    'writeBinay.Write(value2)
    fs.WriteByte(value2)
    'writeBinay.Close()

    br.Close()

    fStream.Close()

私もこれを試しました:

    Dim fLocation = ("Option.mco")

    Dim writeStream As New FileStream(fLocation, FileMode.Create)
    Dim writeBinay As New BinaryWriter(writeStream)

    Dim value As Short = 1600
    Dim value2 As Short = 900
    writeBinay.Seek(39, SeekOrigin.Begin)
    writeBinay.Write(value)
    writeBinay.Seek(43, SeekOrigin.Begin)
    writeBinay.Write(value2)
    writeBinay.Close()

これはファイルのバイトです: http://puu.sh/3nxrd.jpg

4

1 に答える 1