日期:2014-05-18  浏览次数:21017 次

在文本文件加入一行记录(文件操作)
在文本文件加入一行记录,位置是首行或是指定行。谢了。

------解决方案--------------------
up
------解决方案--------------------
可以把文件按行读出
在指定行插入
再按行存入
------解决方案--------------------
楼上正解
------解决方案--------------------
File.AppendAllText
------解决方案--------------------
你在
using System.IO;

再用
StreamWriter s_write = new StreamWriter(room, true, Encoding.Default);//room是文件的地址
s_write.WriteLine(temp.Trim());// temp是要写入的内容.
------解决方案--------------------
public static void writeLog(string txt)
{
String path = " ";
path= "E:\\Asp.net\\web\\ ";
path = path + "\\log\\ " + DateTime.Now.ToShortDateString() + ".txt ";//DateManage类中提供按指定格式输出日期的方法
if (!File.Exists(path))
{
Stream fsc = File.Create(path);
fsc.Close();
}

Stream fs = File.Open(path, FileMode.Append);

DateTime dt = DateTime.Now;
String time = dt.ToString();

TextWriter tw = new StreamWriter(fs);
tw.WriteLine( "Time: " + time + " " + txt);

tw.Close();
fs.Close();

}
------解决方案--------------------
我mark一下