王彬 程序员 王彬 ASP PHP C# .NET AJAX 笔记

我的PHP,.NET开源之路

操作文件的一个自定函数:

using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.IO;//文件操作
using System.Text;//编码操作

/// <summary>
/// Files 的摘要说明
/// </summary>

public class Files
{
    
public Files()
    
{
        
//
        
// TODO: 在此处添加构造函数逻辑
        
//
    }


    
public static bool CreatHtmlPage(string[] strNewHtml, string[] strOldHtml, string strModelFilePath,string strHtmlFilePath)
    
{
        
bool Flag = false;
        StreamReader ReaderFile 
= null;
        StreamWriter WriterFile 
= null;
        
string FilePath = HttpContext.Current.Server.MapPath(strModelFilePath);
        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 = strNewHtml.Length;
            
for (int i = 0; i < intLengTh; i++)
            
{
                strFile 
= strFile.Replace(strOldHtml[i], strNewHtml[i]);
            }

            WriterFile 
= new StreamWriter(HttpContext.Current.Server.MapPath(strHtmlFilePath), false, code);
            WriterFile.Write(strFile);
            Flag 
= true;

        }

        
catch (Exception ex)
        
{
            
throw ex;
        }


        
finally
        
{
            WriterFile.Flush();
            WriterFile.Close();
        }

        
return Flag;
    }

}

posted on   wangbin  阅读(241)  评论(0编辑  收藏  举报
编辑推荐:
· 用 C# 插值字符串处理器写一个 sscanf
· Java 中堆内存和栈内存上的数据分布和特点
· 开发中对象命名的一点思考
· .NET Core内存结构体系(Windows环境)底层原理浅谈
· C# 深度学习:对抗生成网络(GAN)训练头像生成模型
阅读排行:
· 手把手教你更优雅的享受 DeepSeek
· AI工具推荐:领先的开源 AI 代码助手——Continue
· 探秘Transformer系列之(2)---总体架构
· V-Control:一个基于 .NET MAUI 的开箱即用的UI组件库
· 乌龟冬眠箱湿度监控系统和AI辅助建议功能的实现

< 2008年1月 >
30 31 1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30 31 1 2
3 4 5 6 7 8 9
点击右上角即可分享
微信分享提示