//向txt写内容
public void WriteTxt(string content)
{
FileStream myStream = new FileStream(Server.MapPath("~/ProjectTest/commandLog.txt"), FileMode.Append, FileAccess.Write);
StreamWriter sWriter=new StreamWriter(myStream);
sWriter.WriteLine(content);
sWriter.Close();
myStream.Close();
}
//读取txt文件内容
public string GetTxtString( )
{
StreamReader objReader = new StreamReader(Server.MapPath("~/ProjectTest/commandLog.txt"));
string sLine = "";
sLine = objReader.ReadToEnd();
objReader.Close();
return sLine;
public void ClearTxt()
{
FileStream myStream = new FileStream(Server.MapPath("~/ProjectTest/commandLog.txt"), FileMode.Create, FileAccess.Write);
StreamWriter sWriter = new StreamWriter(myStream);
sWriter.WriteLine("");
sWriter.Close();
myStream.Close();
}
public void WriteTxt(string content)
{
FileStream myStream = new FileStream(Server.MapPath("~/ProjectTest/commandLog.txt"), FileMode.Append, FileAccess.Write);
StreamWriter sWriter=new StreamWriter(myStream);
sWriter.WriteLine(content);
sWriter.Close();
myStream.Close();
}
//读取txt文件内容
public string GetTxtString( )
{
StreamReader objReader = new StreamReader(Server.MapPath("~/ProjectTest/commandLog.txt"));
string sLine = "";
sLine = objReader.ReadToEnd();
objReader.Close();
return sLine;
}
//分行读取txt文件内容
public List<string> GetTxtLine()
{
List<string> list=new List<string>();
StreamReader objReader = new StreamReader(Server.MapPath("~/ProjectTest/commandLog.txt"));
var line = "";
while ((line = objReader.ReadLine()) != null)
{
list.Add(line);
}
return list;
}
//清空txtpublic void ClearTxt()
{
FileStream myStream = new FileStream(Server.MapPath("~/ProjectTest/commandLog.txt"), FileMode.Create, FileAccess.Write);
StreamWriter sWriter = new StreamWriter(myStream);
sWriter.WriteLine("");
sWriter.Close();
myStream.Close();
}