我用c#读取BT种子文件的信息,CS1061: “System.IO.StreamReader”不包含“Length”的定义代码如下using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.IO;
using System.Collections;using System.Collections.Generic;
using System.Text; private void TorrentFile(object sender, EventArgs e)         
        {
          StreamReader TorrentFile = new StreamReader("btzz.torrent");
   
           
            byte[] TorrentBytes = new byte[TorrentFile.Length];
            TorrentFile.Read(TorrentBytes, 0, TorrentBytes.Length);
            TorrentFile.Close();
           
            if ((char)TorrentBytes[0] != 'd')
            {                if (OpenError.Length == 0) OpenError = "错误的Torrent文件,开头第1字节不是100";
                return;
            }
            GetTorrentData(TorrentBytes);
        }

解决方案 »

  1.   

    请高手帮我看看,btzz.torrent这个是BT种子文件,报错相信内容为
    编译器错误消息: CS1061: “System.IO.StreamReader”不包含“Length”的定义,并且找不到可接受类型为“System.IO.StreamReader”的第一个参数的扩展方法“Length”(是否缺少 using 指令或程序集引用?)源错误: 行 147:
    行 148:           
    行 149:            byte[] TorrentBytes = new byte[TorrentFile.Length];
    行 150:            TorrentFile.Read(TorrentBytes, 0, TorrentBytes.Length);
    行 151:            TorrentFile.Close();
     由于代码太长,发不上来
      

  2.   

    谢谢,那要用什么方法读取才有length属性,请给个例子,谢谢
      

  3.   

    你这行代码就错了StreamReader TorrentFile = new StreamReader("btzz.torrent");
    这里StreamReader 应该是从特定的字节流中读取。
    如果你只是读取文件的话应该是:
    [code=C#]
    FileStream fs = FileStream("种子文件", FileMode.Open, FileAccess.Read, FileShare.Read);
    byte[] data = new byte[fs.Length];fs.Read (data, 0, data.Length);                code]
      

  4.   

    using(FileStream fs = new FileStream(strFile, FileMode.Open, FileAccess.Read))
    {
    StreamReader sr= new StreamReader(fs);
    sr.BaseStream.Seek(0, SeekOrigin.Begin);
    string strLine = sr.ReadLine();
    while (strLine != null)
    {
      strLine = sr.ReadLine();
    }
    sr.Close();
    }
      

  5.   


    类似于:using(var f= File.OpenRead("asdfadsfasdfs.xxx"))
      using(var TorrentFile = new StreamReader(f))
      {
       ........
      }
      

  6.   

    象你这样的写,不用StreamReader,直接用System.IO.File.ReadAllBytes就可以了。
    byte[] TorrentBytes = File.ReadAllBytes("btzz.torrent");if ((char)TorrentBytes[0] != 'd')
      {  if (OpenError.Length == 0) OpenError = "错误的Torrent文件,开头第1字节不是100";
      return;
      }
      GetTorrentData(TorrentBytes);
      }