本帖最后由 nh1850320185 于 2012-11-22 15:27:51 编辑

解决方案 »

  1.   

    一段时间没来,
    CSDN现在就成这样了
      

  2.   

    作业就不要上来了,自己慢慢参考吧!凡事都要第一次尝试
    Winform读写文件实例
    导出文件夹下所有CS文件的内容到txt文件中
     
            /// <summary>
            /// 功能:合并导入文件夹下的CS代码
            /// </summary>
            /// <param name="dirParent"></param>
            private void UniteCode(DirectoryInfo dirParent)
            {
                string strCreatPath = txtCreatPath.Text.Trim();//@"D:Code.txt";            string strExt = "*.cs";//"*.aspx.cs";                                //过滤条件
                FileInfo[] arrfiInfo =  dirParent.GetFiles(strExt);
                DirectoryInfo[] arrdirChild = dirParent.GetDirectories();            string strFileName ;                                        //文件名称            StreamReader srReader =    null;
                StreamWriter swWriter = null;    
                string strLine ;                                        //读取的一行的数据            try
                {
                    foreach(FileInfo fiInfo in arrfiInfo)
                    {
                        strFileName = fiInfo.FullName;                                                            //文件的名称
                        srReader = new StreamReader(strFileName,System.Text.Encoding.GetEncoding("gb2312"));    //打开一个数据流
                        swWriter = new StreamWriter(strCreatPath,true,System.Text.Encoding.GetEncoding("gb2312"));                    swWriter.WriteLine("");
                        swWriter.WriteLine("/**********************************************************************/");
                        swWriter.WriteLine("文件名:" + strFileName);
                        swWriter.WriteLine("/**********************************************************************/");                    while( (strLine = srReader.ReadLine()) != null)
                        {
                            swWriter.WriteLine(strLine);                
                        }
                        swWriter.Close();
                        swWriter = null;
                        srReader.Close();
                        srReader = null;
                    }
                    
                    foreach( DirectoryInfo dirInfo in arrdirChild )
                    {
                        UniteCode(dirInfo);
                    }                
                }
                catch(Exception err)
                {
                    MessageBox.Show(err.Message.ToString());
                }
                finally
                {            
                }
            }        //选择目录
            private void btnSelect_Click(object sender, System.EventArgs e)
            {
                string strIniDir = "";    //初始化目录
                DialogResult dlgResult;            strIniDir = "C:/Inetpub/wwwroot";            
                fbdDirectory.SelectedPath = strIniDir;
                fbdDirectory.Description = "请选择文件目录";
                dlgResult = fbdDirectory.ShowDialog();
                if( dlgResult == DialogResult.OK )
                {                
                    txtFilePath.Text = fbdDirectory.SelectedPath;                
                }
            }        //导出文件
            private void btnSubmit_Click(object sender, System.EventArgs e)
            {
                if(txtFilePath.Text.Trim().Length > 0 && txtCreatPath.Text.Trim().Length > 0)
                {
                    UniteCode(new DirectoryInfo(fbdDirectory.SelectedPath));
                    MessageBox.Show("导出完毕!");
                }
            }
      

  3.   


    能不能告诉俺一下RichiTextBox 是什么?还有 Open、FileStream、StreamRead、StreamWriter
    这都是什么  干啥用的?
      

  4.   

    Rich=富,Text=文本,Box=框,Open=打开,File=文件,Stream=流,Stream=流, Reader=能读入的东东,
    Writer=能写的东东
      

  5.   


    什么跟什么啊,英文也一般般啊RichTextBox 富文本框     Rich 丰富的  Text 文本  Box 盒子状
            
      

  6.   

    Rich 富豪
    Text 课文
    Box 盒子
    Reader 读者
    Writer 作者
    Stream 小溪