日期:2014-05-17  浏览次数:20471 次

在分析完成之前就遇到流结尾?
public static object ByteToObject(byte[] bytes)
  {
  System.IO.MemoryStream stream = new System.IO.MemoryStream(bytes);
  System.Runtime.Serialization.IFormatter bf = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();
  Object reobj = bf.Deserialize(stream);
  stream.Close();
  return reobj;
  }

在分析完成之前就遇到流结尾。


怎么回事

------解决方案--------------------
把这句加在Deserialize那句之前试试:

stream.Position = 0;
------解决方案--------------------
引用:
这是在数据库读取二进制数据, 然后就‘在分析完成之前就遇到流结尾’遇到这个问题。


????System.Runtime.Serialization.IFormatter 你数据库里存的难道是类?
------解决方案--------------------
 Response.ContentEncoding = System.Text.Encoding.Default;
        Response.ContentType = "rar";
        Response.AddHeader("Content-Disposition", "attachment; filename=" 1.rar");
        Response.BinaryWrite(bytes);