WinCE的C#中使用StreamReader 来读取TXT文档,读取文本文档。
时间:2014-06-22 20:27:57
收藏:0
阅读:317
using System.IO;
private void button1_Click(object sender, EventArgs e) { string strFilePath = ""; OpenFileDialog fd = new OpenFileDialog(); fd.Filter = "文本文件(*.txt)|*.txt|All files (*.*)|*.*"; //过滤文件类型 //fd.InitialDirectory = Application.StartupPath + "\\Temp\\";//设定初始目录 //fd.ShowReadOnly = true; //设定文件是否只读 if (fd.ShowDialog() != DialogResult.OK) { return; } strFilePath = fd.FileName; if (!File.Exists(strFilePath)) { MessageBox.Show("抱歉!文件不存在,请重新输入文件名!"); return; } StreamReader strReader = new StreamReader(new FileStream(strFilePath, FileMode.Open, FileAccess.ReadWrite), Encoding.Default); //string strTemp = strReader.ReadLine(); string strTemp = strReader.ReadToEnd(); strReader.Close(); textBox1.Text = strTemp; }
评论(0)