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();
}
查看全文
相关阅读:
DevOps Workshop 研发运维一体化(北京第二场) 2016.04.27
DevOps Workshop 研发运维一体化(成都站) 2016.05.08
TFS 2015 生成不输出任何结果
挂起的更改中的“解析”是什么意思?原来是微软错误的翻译
微软研发流程(ALM)管理培训会议(比亚迪汽车)
TFS实战培训
【实战TFS】【QQ群】了解别人是如何使用TFS的
DevOps Workshop 研发运维一体化(广州站)
制作Visual Studio 2017 (VS 2017) 离线安装包
在每页(分页)报表中重复显示标题
原文地址:https://www.cnblogs.com/wf225/p/571768.html
最新文章
深入浅出Redis
爬虫实战
上海艾弟尔数字科技有限公司
Split Shape by Plane in OpenCASCADE
GLUT Trackball Demo
AVEVA PDMS to 3ds Max
Bounding Volume Hierarchy BVH in OpenCASCADE
Use PSO to find minimum in OpenCASCADE
Intersection between 2d conic in OpenCASCADE
Intersection between a 2d line and a conic in OpenCASCADE
热门文章
基本类型、引用类型、基本包装类型和单体内置对象
js函数中的apply()、call()、bind()方法
callee和caller属性的区别
元素居中显示
函数arguments对象
一切皆为框——行内元素和块级元素
css float(浮动)
css position(定位)
转换为字符串方法
数值转换
Copyright © 2011-2022 走看看