public
void
WriteToTxt(
string
messege)
{
StreamWriter srd = null ;
string path = @" c:/MyTest.txt " ;
try
{
if ( ! File.Exists(path))
{
// 创建文件
srd = File.CreateText(path); } else
{
// 以追加的形式读写该文件
FileStream fs = new FileStream(path, FileMode.Append, FileAccess.Write);
srd = new StreamWriter(fs);
}
srd.WriteLine(messege);
srd.Close();
}
catch (Exception ex)
{
throw new Exception( " 写入失败! " );
return ;
}
}
{
StreamWriter srd = null ;
string path = @" c:/MyTest.txt " ;
try
{
if ( ! File.Exists(path))
{
// 创建文件
srd = File.CreateText(path); } else
{
// 以追加的形式读写该文件
FileStream fs = new FileStream(path, FileMode.Append, FileAccess.Write);
srd = new StreamWriter(fs);
}
srd.WriteLine(messege);
srd.Close();
}
catch (Exception ex)
{
throw new Exception( " 写入失败! " );
return ;
}
}