if (!File.Exists(path)) { // Create the file. using (FileStream fs = File.Create(path)) { Byte[] info = new UTF8Encoding(true).GetBytes("This is some text in the file."); //根据你的文件的具体编码方式来具体选择,不然要乱码的。 // Add some information to the file. fs.Write(info, 0, info.Length); } } // Open the stream and read it back. using (StreamReader sr = File.OpenText(path)) { StringBuilder myStr = new StringBuilder(0,11000000); //public StringBuilder(int capacity,int maxCapacity); myStr.Append(sr.readLine());
{
// Create the file.
using (FileStream fs = File.Create(path))
{
Byte[] info =
new UTF8Encoding(true).GetBytes("This is some text in the file."); //根据你的文件的具体编码方式来具体选择,不然要乱码的。 // Add some information to the file.
fs.Write(info, 0, info.Length);
}
} // Open the stream and read it back.
using (StreamReader sr = File.OpenText(path))
{
StringBuilder myStr = new StringBuilder(0,11000000);
//public StringBuilder(int capacity,int maxCapacity);
myStr.Append(sr.readLine());
}就应该把最早写入的日志文件的内容删除一部分,删除部分的大小等于本次写入内容的大小这个你就自己设计一个算法吧,你可以把myStr里的内容先反转,让最早加入的排在最前面,然后按你的要求删掉相应的字符数,然后再反转回去,新建一个文件把你今天的日志STRING+myStr加进去,最后删掉原来的日志文件。楼上Sunmast(速马, Reloading...) 说的可能是这个
http://chs.gotdotnet.com/quickstart/util/srcview.aspx?path=/quickstart/howto/samples/IO/logfile/logfile.srchttp://chs.gotdotnet.com里有很多基础内容,最好没事去看看,不要以为仅仅是个入门哦。
温故知新,呵呵。