如果该物理路径没有该文本则创建一个新文本
if (!File.Exists(@"C:\db.txt"))
{
FileStream fs = new FileStream(@"C:\db.txt", FileMode.Create);
fs.Close();
}
//读取文本,遍历文本
StreamReader sr = new StreamReader(@"C:\db.txt", Encoding.GetEncoding("gb2312"));
string nextLine;
while ((nextLine = sr.ReadLine()) != null)
{
MessageBox.Show(nextLine);
}
//在最后一行写入数据,(如果需要在特定行则需要另外方法http://www.cnblogs.com/wdw31210/p/3179257.html)
StreamWriter sw = new StreamWriter(@"C:\db.txt", true, encoding: Encoding.GetEncoding("GB2312"));
sw.Write("\r\n"+"哈哈哈");
sw.Flush();
sw.Close();