我真的很喜欢.NET如何将二进制数据读/写到文件中。干净而优雅。
我可以用Python做到这一点吗?
Sub Main()
Using writer As New System.IO.BinaryWriter( _
System.IO.File.Open("Test.bin", IO.FileMode.Create))
writer.Write(True)
writer.Write(123)
writer.Write(123.456)
writer.Write(987.654D)
writer.Write("Test string.")
End Using
Using reader As New System.IO.BinaryReader( _
System.IO.File.Open("Test.bin", IO.FileMode.Open))
Console.WriteLine(reader.ReadBoolean())
Console.WriteLine(reader.ReadInt32())
Console.WriteLine(reader.ReadDouble())
Console.WriteLine(reader.ReadDecimal())
Console.WriteLine(reader.ReadString())
End Using
Console.Write("Press <RETURN> to exit.")
Console.ReadKey()
End Sub