zoukankan
html css js c++ java
文件创建及读取的方法
以前创建用
String filePath
=
HttpContext.Current.Server.MapPath(FileName);
if
(
!
System.IO.File.Exists(filePath))
//
创建文件
System.IO.File.Create(filePath);
System.IO.StreamWriter sw
=
new
System.IO.StreamWriter(filePath,
false
);
sw.WriteLine(html);
sw.Close();
读取用
if
(System.IO.File.Exists(filePath))
{
//
System.IO.FileStream fs = System.IO.File.OpenRead(filePath);
FileStream fs
=
new
FileStream(filePath, FileMode.Open, FileAccess.Read, FileShare.Read);
StreamReader sr
=
new
StreamReader(filePath, System.Text.Encoding.UTF8);
//
StreamReader sr = new StreamReader(filePath);
while
(sr.Peek()
>
-
1
)
//
StreamReader.Peek()返回下一个可用字符,但不使用它
{
Response.Write(sr.ReadLine());
}
sr.Close();
fs.Close();
}
如果文件不存在的话,就会有
文件“G:\wwwRoot\wufengBS\文件处理\code.xls”正由另一进程使用,因此该进程无法访问该文件。
的错误。
改用流创建即可:
if
(
!
System.IO.File.Exists(filePath))
//
创建文件
{
System.IO.FileStream fs
=
System.IO.File.Create(filePath);
fs.Close();
}
查看全文
相关阅读:
git 删除远程分支
测试模板--接口测试
测试模板--PC浏览器兼容性测试
Mock作用
Docker实践--搭建JIRA平台
Docker实践--搭建分布式UI测试环境
Docker实践--搭建HttpRunnerManager测试平台
Docker实践--搭建Yapi测试平台
微博爬虫实践---搜索关键词
接口实践--演练地址集合
原文地址:https://www.cnblogs.com/wf225/p/571768.html
最新文章
在线预览doc, docx, xls, xlsx, ppt, pptx
不定长参数
Django REST framework使用
django外键中的on_delete
rem自适应布局
数组快速遍历
递归小案例
js闭包理解
清除浮动的几种方式
video3
热门文章
myBatis学习笔记
Mac在Finder中显示隐藏文件
Ubuntu在更新时提示/boot空间不足
64位Ubuntu14.04安装sogou拼音
libiconv build in android
ubuntu下修改文件或者文件夹所有者和组
ubuntu添加qmake 出现错误 qmake: could not exec '/usr/lib/x86_64-linux-gnu/qt4/bin/qmake': No such file or directory
ubuntu 下git commit error insufficient permission for adding an object to repository database .git/objects错误 解决方法
当qml文件添加到qrc文件中,实现internationalization(国际化)
添加工程到creator编辑器步骤
Copyright © 2011-2022 走看看