【发布时间】:2013-01-04 18:32:56
【问题描述】:
我正在尝试在内存中创建文本文件并将其写入byte[]。我该怎么做?
public byte[] GetBytes()
{
MemoryStream fs = new MemoryStream();
TextWriter tx = new StreamWriter(fs);
tx.WriteLine("1111");
tx.WriteLine("2222");
tx.WriteLine("3333");
tx.Flush();
fs.Flush();
byte[] bytes = new byte[fs.Length];
fs.Read(bytes,0,fs.Length);
return bytes;
}
但由于数据长度问题,它不起作用
【问题讨论】:
-
MemoryStream 类型的对象具有属性“ToArray()”。在那里你得到字节[]
-
这对您有帮助吗stackoverflow.com/questions/221925/… ?
-
@yan.kun 关闭的原件在关闭时只有第一行。此后,他添加了更多信息,并且出于某种原因发布了此副本。