Last active
December 17, 2015 21:39
-
-
Save Vincentxiaojie/5676383 to your computer and use it in GitHub Desktop.
逐行读取文本信息,下载文件
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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