我有以下代码:
byte[] snapthotBytes, snapthotBytes2;
string stringOutput, stringOutput2;
IInvestigationDump investigationDump = new HtmlSnapshotDump();
using (TextWriter writer = new StringWriter())
{
investigationDump.Dump(investigation, writer);
snapthotBytes = Encoding.UTF8.GetBytes(writer.ToString());
stringOutput = writer.ToString();
} // end of first implementation
using (MemoryStream stream = new MemoryStream())
using (TextWriter writer = new StreamWriter(stream))
{
investigationDump.Dump(investigation, writer);
stream.Seek(0, SeekOrigin.Begin);
var reader = new StreamReader(stream);
stringOutput2 = reader.ReadToEnd();
snapthotBytes2 = stream.ToArray();
} // end of second implementation
// stringOutput != stringOutput2 - content wise
// snapthotBytes != snapthotBytes2 - content wise导言:
void Dump(IInvestigation investigation, TextWriter writer);
。
起初,我使用了MemoryStream代码片段,因为我直接收到了byte[]代码片段,这样就更容易了。但很快我发现了一个窃听器。令人惊讶的是,stringOutput2 (由MemoryStream解决方案生产)被裁剪,它更短了!它只是以修剪过的HTML内容结束:
<tr>
<td>Certificate or License No</td>
<td class="value">Friuan</td>
<td>Place of Issue</td>
<td class="value">Foruan</td>
</tr>
<tr>
<td>Award Date</td>
<td 发布于 2011-12-01 10:41:44
怎么样
writer.Flush()在试着读溪流之前?
https://stackoverflow.com/questions/8339941
复制相似问题