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();
}
查看全文
相关阅读:
django-3-模板变量,过滤器,静态文件的引用
django-2-路由配置及渲染方式
用pycharm运行django项目
django-1-框架介绍
django-6-数据库配置及模型创建,激活(django模型系统1)
用Sklearn实现聚类算法并用散点图展现效果
方差、标准差、协方差、协方差相关系数
ARIMa--时间序列模型
人工智能--第二天--KNN算法实现
人工智能--第二天--KNN算法
原文地址:https://www.cnblogs.com/wf225/p/571768.html
最新文章
windows下R语言更新
R语言 range()函数
perl脚本:读取fasta序列
perl脚本:cds序列转换为pep
perl数组去重
通过systemback制作镜像并安装
清理云服务器挖矿程序--kdevtmpfsi
Django QuerySet缓存和惰性机制
在使用selenium时出现FileNotFoundError: [WinError 2] 系统找不到指定的文件。
E: 无法获得锁 /var/lib/dpkg/lock
热门文章
[转载]Python 魔法方法详解
对CSRF(跨站请求伪造)的理解
记事本问题
Python第三方库资源
Linux目录结构解释
django-10-中间件和上下文管理器
django-9-请求与响应
django-8-django模型系统
django-7-django模型系统
django-4-模板标签,模板继承
Copyright © 2011-2022 走看看