C#读写文本文件
时间:2011-03-01 来源:追梦百合
//写文本文件
FileStream fs = new FileStream(@ "c:\myfile.txt ",FileMode.Create);
StreamWriter writer = new StreamWriter(fs);
writer.WriteLine( "The first line here ");
writer.WriteLine( "The second line here ");
writer.WriteLine( "ending now ");
writer.Flush();
fl.Close();
//读取文本文件:
StreamReader objReader = new StreamReader("c:\\myfile.txt",Encoding.Default);
string sLine="";
ArrayList arrText = new ArrayList();
while (sLine != null)
{
sLine = objReader.ReadLine();
if (sLine != null)
arrText.Add(sLine);
}
objReader.Close();
foreach (string sOutput in arrText)
Console.WriteLine(sOutput);
Console.ReadLine();
相关阅读 更多 +