zoukankan
html css js c++ java
IO流读取与写入文件+SQL替换更新字段脚本
//流读取写入文件
读取文件
//
读文件操作
string
strFileContent
=
""
;
//
模版文件的全文内容
try
{
string
strLine
=
""
;
//
每行的内容
//
使用垃圾回收对该资源进行自动处置using就不用关闭对象,否则必须关闭strFileFullName文件路径。
using
(StreamReader fileRead
=
new
StreamReader(strFileFullName,Encoding.Default))
{
while
(fileRead.Peek()
>=
0
)
{
strLine
=
fileRead.ReadLine();
strFileContent
+=
strLine;
}
}
}
写入文件
//
写文件操作
//
为了保证文件的格式,替换部分字符串
strFileContent
=
strFileContent.Replace(
"
\t
"
,
"
\r\n\t
"
);
string
strErrmsg;
string
path;
if
(
!
File.Exists(strFileFullName))
{
//
strFileFullName文件物理路径
path
=
strFileFullName.Replace(
"
\\demo.txt
"
,
""
);
//
DirectoryInfo公用创建、移动、和枚举的实例方法
DirectoryInfo di
=
Directory.CreateDirectory(path);
//
创建文件以UTF-8的编码形式
StreamWriter sr
=
File.CreateText(strFileFullName);
sr.Close();
}
try
{
System.IO.StreamWriter fileWrite
=
new
StreamWriter(strFileFullName,
false
,Encoding.Default);
//
strFileContent 文件内容
fileWrite.Write(strFileContent);
fileWrite.Close();
}
//更新替换字段
update
UserInfo
set
URL_Name
=
(
select
replace
(URL_Name,
substring
(URL_Name,
0
,
17
),
'
http://hanguoji
'
))
where
substring
(URL_Name,
0
,
17
)
=
'
http://localhost
'
查看全文
相关阅读:
这一段
转安装vs2003 提示重启
转解决VSS中Access to file "rights.dat" denied的错误
C# 页面基类
C#密码加密
转 如何改变*.sln文件的路径
后台为按钮定义js事件
sql2005 数据库还原
vss 代码管理器
转 如何有效的使用C#读取文件 及如何解决中文乱码问题
原文地址:https://www.cnblogs.com/hanguoji/p/439908.html
最新文章
2011孕妇奶粉排行榜
Beginning Storyboards in iOS 5 Part 1
Using Storyboards To Create A Single View Application
iPhone开发重构:提取公用的方法以清理重复代码 【转】
Adding a custom image to a UITableView delete button
Migrating your code to ObjectiveC ARC
mac svn命令 linux同样适用【转】
iPhone开发重构:提取方法以调整函数粒度【转】
Understanding Automatic Reference Counting in ObjectiveC
Developer location setting in Xcode 4.3.2
热门文章
Mac系统升级ruby的一些命令
iPhone开发重构:提取方法以调整抽象层次【转】
Everything you need to know about automatic reference counting (ARC)
[原创] Learning in Python:Chapter 3 How You Run Programs
[原创] Learning in Python:Chapter 2 How Python Runs Programs
浅谈Java中15种锁的分析比较
深入Redis 主从复制的原理
ZooKeeper 一致性协议 ZAB 原理
RDB 和 AOF 持久化的原理是什么?我应该用哪一个?它们的优缺点?
MySQL每秒57万的写入,带你飞
Copyright © 2011-2022 走看看