如何实时显示一个文本文件增加的内容

universeliu 2004-11-21 04:30:22
我想实时显示一个日志文件新增的内容,类似于unix的tail -f 命令,请高手指教
...全文
175 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
chenyuming2004 2004-11-22
  • 打赏
  • 举报
回复
使用FileSystemWatcher组件监视文件内容变化,
发生变化时,
把文件内容读入文本框中去。
看看对你有没有帮助。
chenyuming2004 2004-11-22
  • 打赏
  • 举报
回复
private void Form4_Load(object sender, System.EventArgs e)
{
FileSystemWatcher fsw=new FileSystemWatcher();
fsw.Path=@"e:\";
fsw.Filter="log.txt";
fsw.NotifyFilter=System.IO.NotifyFilters.LastWrite;
fsw.Changed+=new FileSystemEventHandler(FileChange);
fsw.EnableRaisingEvents=true;
}


private void FileChange(object sender,FileSystemEventArgs e)
{
StreamReader sr=new StreamReader(@"e:\log.txt",System.Text.Encoding.Default);
textBox1.Text=sr.ReadToEnd();
sr.Close();
}

110,533

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧