简体   繁体   English

如何使用BinaryWriter获取写入字节的长度?

[英]How to get the length of written bytes with BinaryWriter?

Considering a simple BinaryWriter procedure: 考虑一个简单的BinaryWriter过程:

using (BinaryWriter writer = new BinaryWriter(File.Open(fileName, FileMode.Create)))
        {
            writer.Write(10000);
            writer.Write("Temp");
            writer.Write(30);
            writer.Write(50.6);
        }

Now, how can I get the total number of written bytes by the BinaryWriter? 现在,如何获取BinaryWriter写入的字节总数? And how to append this amount to the current writer object, eg writer.Write(totalNumberAsBytes) 以及如何将此金额追加到当前writer对象,例如writer.Write(totalNumberAsBytes)

Have you tried writer.BaseStream.Length ? 您是否尝试过writer.BaseStream.Length This should be the amount of bytes in the stream. 这应该是流中的字节数。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我如何修改使用 binarywriter 写入的内存流中的一小部分字节 - how can i modify a small section of bytes in a memory stream, that was written to using binarywriter 如何成功写入字节数? - How to get number of bytes written successfully? 如何确定 BinaryWriter 写入 memory 需要多少字节? - How to determine how many bytes a BinaryWriter would take to write into memory? .NET System.IO.BinaryWriter写入的原始字节是否可以被其他平台读取? - Are the raw bytes written by .NET System.IO.BinaryWriter readable by other platforms? 使用Binarywriter写空字节 - Write empty bytes using binarywriter 获取以字节为单位的大小,当写入文件时,该字符串将占用多少? - Get the size, in bytes, of how much a string will occupy when written to a file? 如何从 .NET 的 BinaryWriter 序列化的四个字节中读取单精度浮点数 - How to read a single-precision floating-point number from four bytes serialized by .NET's BinaryWriter 响应内容长度不匹配:写入的字节太少 - Response Content-Length mismatch: too few bytes written 如何优化我的BinaryWriter? - How to optimize my BinaryWriter? 如何在哈希表上使用Binarywriter? - How to use binarywriter on hashtable?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM