【发布时间】:2017-12-09 06:39:08
【问题描述】:
我正在寻找可以将 System.IO.Stream 转换为 byte[] 的 C# 语言解决方案。我已经尝试了下面的代码,但我收到的 byte[] 为空。有人可以指导我从下面的代码中缺少什么吗?我从 Alfresco Web 服务接收,除非保存到临时位置,否则我无法读取文件。
private static byte[] ReadFile(Stream fileStream)
{
byte[] bytes = new byte[fileStream.Length];
fileStream.Read(bytes, 0, Convert.ToInt32(fileStream.Length));
fileStream.Close();
return bytes;
//using (MemoryStream ms = new MemoryStream())
//{
// int read;
// while ((read = fileStream.Read(bytes, 0, bytes.Length)) > 0)
// {
// fileStream.CopyTo(ms);
// }
// return ms.ToArray();
//}
}
【问题讨论】:
-
流可以很大(大于允许的数组大小),甚至无限大;一般来说,这不是一个好主意!
标签: c# byte alfresco filestream