VB.NET写文件时数据丢失


调用这个子程序保存地图文件时,循环正常进行但Write只写了一次,最终输出的文件只有17字节。试过WriteAllBytes但问题依旧。有什么解决方法吗?
(TileArray是一个Byte数组)


 Public Sub Save(ByVal FilePath As String)
    Dim fs As New IO.FileStream(FilePath, IO.FileMode.OpenOrCreate, IO.FileAccess.Write)
    Dim br As New IO.BinaryWriter(fs)
    Dim blank As Byte = 0
    br.Write(ReaderFx) '00
    br.Write(MapBack.R) '01
    br.Write(MapBack.G) '02
    br.Write(MapBack.B) '03
    br.Write(MapWidth >> 8) '04
    br.Write(MapWidth And &HFF) '05
    br.Write(blank) '06
    br.Write(blank) '07
    br.Write(blank) '08
    br.Write(blank) '09
    br.Write(blank) '0A
    br.Write(blank) '0B
    br.Write(blank) '0C
    br.Write(blank) '0D
    br.Write(blank) '0E
    br.Write(blank) '0F

    Dim debugtemp = 0
    For Each i In TileArray
        br.Write(i)
        debugtemp = debugtemp + 1
    Next
    MsgBox(debugtemp)
    br.Flush()
    br.Close()
End Sub

.net

新酱小苦逼 9 years, 9 months ago

问题可能出在循环上,你可以尝试使用 writeallbytes() 方法,请参考

https://msdn.microsoft.com/zh-cn/libr...

西红柿妖梦 answered 9 years, 6 months ago

Your Answer