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();
}
查看全文
相关阅读:
Unity使Text 文字逐个出现
Mybatis入门
sqoop工具介绍(hdfs与关系型数据库进行数据导入导出)
MapReduce经典入门小案例
hdfs的java接口简单示例
Mac环境下安装配置Hadoop伪分布式
【转】深入理解javascript原型和闭包(完结)
javascript面向对象一:函数
【转】sql语句的优化分析
【转】java调用存储过程和函数
原文地址:https://www.cnblogs.com/wf225/p/571768.html
最新文章
bzoj
The 15th Zhejiang Provincial Collegiate Programming Contest 训练报告
codeforces 962D Merge Equals
codeforces 962C Make a Square
codeforces 962B Students in Railway Carriage
codeforces 962A Equator
codeforces 961E Tufurama
codeforces 961D Pair Of Lines
codeforces 961C Chessboard
codeforces 961B Lecture Sleep
热门文章
codeforces 961A Tetris
win10命令控制符
C#连接SQLServer数据库
java (Eclipse)连接MySQL数据库
SQL语句
unity震动效果
unity材质球贴图滚动
Unity射线
unity对象物体闪烁
unity中Animation与Animator的区别
Copyright © 2011-2022 走看看