Skip to content

Instantly share code, notes, and snippets.

@Vincentxiaojie
Last active December 17, 2015 21:39
Show Gist options
  • Save Vincentxiaojie/5676383 to your computer and use it in GitHub Desktop.
Save Vincentxiaojie/5676383 to your computer and use it in GitHub Desktop.
逐行读取文本信息,下载文件
class Program
{
static void Main(string[] args)
{
string path = AppDomain.CurrentDomain.BaseDirectory + "pic.txt";
using (StreamReader sr = new StreamReader(path))
{
WebClient mywebclient = new WebClient();
string line;
while (!string.IsNullOrEmpty(line = sr.ReadLine()))
{
if (string.Equals(line, "null", StringComparison.OrdinalIgnoreCase))
{
continue;
}
string newfilename = line.Replace("http://#:81/pic/", "");
string filepath = @"D:\Website\#\pic\" + newfilename;
try
{
mywebclient.DownloadFile(line, filepath);
//filename = newfilename;
}
catch (Exception ex)
{
}
Console.WriteLine(line);
}
}
Console.WriteLine(path);
Console.ReadLine();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment