【发布时间】:2018-11-12 00:41:54
【问题描述】:
我一直收到一个错误,比如当我有字符串时,它说它无法将 'byte[]' 转换为字符串。当我将它作为 var 时,它说的是同样的事情,但结果.txt 旁边的数据给我一个错误。
if (Lock.Contains("Mode: Data Grabber"))
{
Console.WriteLine("Loading Data Grabber 2.0! Mode = Data Grabber!\n");
Console.WriteLine("Enter the websites url!\n");
Console.WriteLine("(\n) " + "(\n)");
if (Option == Option)
{
WebClient wc = new WebClient();
string data = wc.DownloadData(Option);
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine("Downloading data from " + data);
Thread.Sleep(3000);
Console.WriteLine("\n");
if (!File.Exists(Directory.GetCurrentDirectory() + @"/Results.txt"))
{
File.Create(Directory.GetCurrentDirectory() + @"/Results.txt");
}
File.WriteAllText(Directory.GetCurrentDirectory() + @"/Results.txt", data);
Console.WriteLine("All data has been sent to the path");
}
}
【问题讨论】:
-
与实际问题无关(使用DownloadString而不是DownloadData),但
if (Option == Option)看起来有点奇怪。 -
请注意
GetCurrentDirectory可以在您的程序运行时更改,并且非管理员无法写入应用程序目录。咨询Error about finding the file ...。