62,272
社区成员
发帖
与我相关
我的任务
分享Encoding code = Encoding.GetEncoding("utf-8");
StreamWriter sw = null;
string str = null;
//读取远程路径
System.Net.WebClient wc = new System.Net.WebClient();
Byte[] pageData = wc.DownloadData(Url);
str = System.Text.Encoding.UTF8.GetString(pageData);
//写入
try
{
if (!Directory.Exists(Server.MapPath(outpath)))//判断文件夹是否存在
{
Directory.CreateDirectory(Server.MapPath(outpath)); //创建文件夹
}
sw = new StreamWriter(Server.MapPath(outpath) + filename, false, code);
sw.Write(str);
sw.Flush();
}
catch (Exception ex)
{
throw ex;
}
finally
{
sw.Close();
}