我用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);
}
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);
}
编译器错误消息: 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();
由于代码太长,发不上来
这里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]
{
StreamReader sr= new StreamReader(fs);
sr.BaseStream.Seek(0, SeekOrigin.Begin);
string strLine = sr.ReadLine();
while (strLine != null)
{
strLine = sr.ReadLine();
}
sr.Close();
}
类似于:using(var f= File.OpenRead("asdfadsfasdfs.xxx"))
using(var TorrentFile = new StreamReader(f))
{
........
}
byte[] TorrentBytes = File.ReadAllBytes("btzz.torrent");if ((char)TorrentBytes[0] != 'd')
{ if (OpenError.Length == 0) OpenError = "错误的Torrent文件,开头第1字节不是100";
return;
}
GetTorrentData(TorrentBytes);
}