1. WPF中读取txt文档并显示在TextBlock上的方法
using System.IO;
StreamReader sr = new StreamReader(@".\tempDesFile.txt");
this.ResultTextBlock.Text = sr.ReadToEnd();
sr.Close();
其中ResultTextBlock为TextBlock显示控件。
2. WPF中清空txt文件内容的方法
using System.IO;
String appDir = @".\tempDesFile.txt";
FileStream stream = File.Open(appDir, FileMode.OpenOrCreate, FileAccess.Write);
stream.Seek(0, SeekOrigin.Begin);
stream.SetLength(0);
stream.Close();