| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 687 人关注过本帖
标题:帮忙解释下这段代码吧
只看楼主 加入收藏
belong0204
Rank: 2
等 级:论坛游民
帖 子:66
专家分:30
注 册:2009-4-9
结帖率:73.33%
收藏
已结贴  问题点数:20 回复次数:4 
帮忙解释下这段代码吧
看了半天,看不懂,各位大哥帮忙解释下吧,谢谢了。

public class Files
{
    public Files()
    {
        //
        // TODO: 在此处添加构造函数逻辑
        //
    }
    public static bool CreatHtmlPage(string[] strNewsHtml, string[] strOldHtml, string strModeFilePath, string strPageFilePath)
    {
        bool Flage = false;
        StreamReader ReaderFile = null;
        StreamWriter WrirteFile = null;
        string FilePath = HttpContext.Current.Server.MapPath(strModeFilePath);
        Encoding Code = Encoding.GetEncoding("gb2312");
        string strFile = string.Empty;
        try
        {
            ReaderFile = new StreamReader(FilePath, Code);
            strFile = ReaderFile.ReadToEnd();

        }
        catch (Exception ex)
        {
            throw ex;
        }
        finally
        {
            ReaderFile.Close();
        }
        try
        {
            int intLengTh = strNewsHtml.Length;
            for (int i = 0; i < intLengTh; i++)
            {
                strFile = strFile.Replace(strOldHtml[i], strNewsHtml[i]);
            }
            WrirteFile = new StreamWriter(HttpContext.Current.Server.MapPath(strPageFilePath), false, Code);
            WrirteFile.Write(strFile);
            Flage = true;
        }
        catch (Exception ex)
        {
            throw ex;
        }
        finally
        {

            WrirteFile.Flush();
            WrirteFile.Close();
        }
        return Flage;
    }
    public static bool UpdateHtmlPage(string[] strNewsHtml, string[] strStartHtml, string[] strEndHtml, string strHtml)
    {
        bool Flage = false;
        StreamReader ReaderFile = null;
        StreamWriter WrirteFile = null;
        string FilePath = HttpContext.Current.Server.MapPath(strHtml);
        Encoding Code = Encoding.GetEncoding("gb2312");
        string strFile = string.Empty;
        try
        {
            ReaderFile = new StreamReader(FilePath, Code);
            strFile = ReaderFile.ReadToEnd();

        }
        catch (Exception ex)
        {
            throw ex;
        }
        finally
        {
            ReaderFile.Close();
        }
        try
        {
            int intLengTh = strNewsHtml.Length;
            for (int i = 0; i < intLengTh; i++)
            {
                int intStart = strFile.IndexOf(strStartHtml[i]) + strStartHtml[i].Length;
                int intEnd = strFile.IndexOf(strEndHtml[i]);
                string strOldHtml = strFile.Substring(intStart, intEnd - intStart);
                strFile = strFile.Replace(strOldHtml, strNewsHtml[i]);
            }
            WrirteFile = new StreamWriter(FilePath, false, Code);
            WrirteFile.Write(strFile);
            Flage = true;
        }
        catch (Exception ex)
        {
            throw ex;
        }
        finally
        {

            WrirteFile.Flush();
            WrirteFile.Close();
        }
        return Flage;
    }
}
搜索更多相关主题的帖子: 解释 代码 
2010-02-01 15:55
qingzhu5753
Rank: 4
等 级:业余侠客
帖 子:64
专家分:248
注 册:2009-10-28
收藏
得分:0 
这是一个类 File,包括两个bool类型的方法CreatHtmlPage和UpdateHtmlPage,当创建网页或更新网页成功时,返回TRUE,否则返回FALSE.这两个方法都是通过数据流的形式读写文件,后边的就是一些简单的读写操作,书上应该有详细的讲.
2010-02-03 14:51
aspic
Rank: 17Rank: 17Rank: 17Rank: 17Rank: 17
等 级:贵宾
威 望:51
帖 子:2258
专家分:8050
注 册:2008-2-18
收藏
得分:20 
哪一句不懂?
2010-02-03 15:14
jiaguofu2005
Rank: 2
等 级:论坛游民
帖 子:47
专家分:59
注 册:2009-9-2
收藏
得分:0 
学习
2010-02-04 08:35
belong0204
Rank: 2
等 级:论坛游民
帖 子:66
专家分:30
注 册:2009-4-9
收藏
得分:0 
方法中传递的参数是怎么来的啊。
2010-02-04 08:36
快速回复:帮忙解释下这段代码吧
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.016606 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved