读取文件和写文件
#region 读取文件
private string ReadFile(string fileName)
{
string fileText = null;
try
{
WebRequest HttpWebRequest = null;
HttpWebRequest = WebRequest.Create(fileName);
using (WebResponse HttpWebResponse = HttpWebRequest.GetResponse())
{
using (StreamReader sr = new StreamReader(HttpWebResponse.GetResponseStream(), Encoding.GetEncoding("gb2312")))
{
fileText = sr.ReadToEnd();
sr.Close();
}
}
}
catch (System.Net.WebException ew)
{
NnllPublic.SetMsgJS(this, "读取文件出错:" + ew.Message);
return "";
}
return fileText;
}
#endregion
#region 生成文件
private bool CreateFile(string fileName,string fileText)
{
bool ok = true;
try
{
using (StreamWriter sw = new StreamWriter(fileName, false, Encoding.GetEncoding("gb2312")))
{
sw.Write(fileText);
sw.Flush();
sw.Close();
}
NnllPublic.SetMsgJS(this, "文件成功生成");
}
catch (Exception ex)
{
ok = false;
NnllPublic.SetMsgJS(this, "写入文件出错:" + ex.Message);
}
return ok;
}
#endregion