本帖最后由 zhouxicai 于 2013-07-01 18:02:59 编辑

解决方案 »

  1.   

     private void button5_Click(object sender, EventArgs e)
            {
                openFileDialog1.ShowDialog(this);
     
                    openFileDialog1.Filter = "LUA文件|*.lua|所有文件|*.*";//设置文件类型;
                    openFileDialog1.AutoUpgradeEnabled = true;//是否随系统升级而升级外观;
                if ( openFileDialog1.ShowDialog(this) ==  System.Windows.Forms.DialogResult.OK)
                {
                    textBox1.Text = openFileDialog1.FileName;
                   Stream read_stream = File.OpenRead(openFileDialog1.FileName);
                    
                    if (File.Exists(openFileDialog1.FileName))//看看文件是否存在;
                    {
                       
                        FileStream fs = File.OpenRead(openFileDialog1.FileName);//存在的话旧打开文件;
                        byte[] str = new byte[20000];//定义数组来读取数据;
                        while (fs.Read(str, 0, str.Length) > 0)//开始从文本中读取数据;
                        {
                            Console.WriteLine(System.Text.Encoding.Default.GetString(str));//将读取的数据写出来 到屏幕上;
     
                            textBox1.Text = System.Text.Encoding.Default.GetString(str);
                             fs.write(textbox1.text);//写进文档
                        }
                        fs.Close();//关闭文件;
                        
                    }
                }
            }
    就你这个代码我估计是成功执行的了,但是里面的数据是没有改的应该你还要把你刚刚读取和改完的数据写进去你的文档那才会真正出效果!加个写进去的代码就行了具体我没试,LZ试下吧