WinCE的C#中使用StreamReader 來讀取TXT文檔,讀取文本文檔。



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; }






免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM