zoukankan
html css js c++ java
个人学习代码保存:例10.通过模板创建静态页面的操作文件的一个自定函数
操作文件的一个自定函数:
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;
}
}
查看全文
相关阅读:
::before和::after伪元素的用法
JS中map、some、every、filter方法
C++多线程,互斥,同步
RAII
Proxy 代理
Decorator 装饰
TCP和UDP的9个区别是什么
谈谈自己对面向对象的理解
C++11多线程
std::move
原文地址:https://www.cnblogs.com/wbcms/p/1037566.html
最新文章
[Leetcode Weekly Contest]172
[Leetcode]645.Set Mismatch
设计模式-外观模式
设计模式--简单工厂模式
C#事件浅淡(1)
Distinct 实现自定义去重
config.xml
拖动窗口
GridSplitter
lable的渲染
热门文章
PassWord控件
后台添加Textbox
一次完整的HTTP请求与响应
HTTP和HTTPS的区别和常见的面试题
HTTP协议详解
Vue事件修饰符
addEventListener和attachEvent的区别(转载)
JavaScript常用类库推荐
javascript常用工具类util.js
Vue中的scoped及穿透方法
Copyright © 2011-2022 走看看