zoukankan
html css js c++ java
c#读取/写入文件
Code
using
System;
using
System.Data;
using
System.Configuration;
using
System.Web;
using
System.Web.Security;
using
System.Web.UI;
using
System.Web.UI.WebControls;
using
System.Web.UI.WebControls.WebParts;
using
System.Web.UI.HtmlControls;
using
System.IO;
public
partial
class
_Default : System.Web.UI.Page
{
protected
void
Page_Load(
object
sender, EventArgs e)
{
}
/**/
///
<summary>
///
检查文件是否存在
///
</summary>
///
<param name="FilePath"></param>
private
void
ExistsFile(
string
FilePath)
{
if
(
!
File.Exists(FilePath))
{
File.Create(FilePath);
}
}
//
读取文件
protected
void
Button2_Click(
object
sender, EventArgs e)
{
ExistsFile(Server.MapPath(
"
~/test/111.txt
"
));
//
读取文件
StreamReader sr
=
new
StreamReader(Server.MapPath(
"
~/test/111.txt
"
), System.Text.Encoding.Default);
try
{
string
input
=
sr.ReadToEnd();
sr.Close();
input
=
input.Replace(
"
<br>
"
,
"
\r\n
"
);
Response.Write(
"
<b>文件读取成功!</b>
"
);
TextBox1.Text
=
input;
}
catch
{
Response.Write(
"
<b>文件读取失败!</b>
"
);
}
}
//
写入文件
protected
void
Button1_Click(
object
sender, EventArgs e)
{
ExistsFile(Server.MapPath(
"
~/test/111.txt
"
));
//
写入文件
StreamWriter sw
=
new
StreamWriter(Server.MapPath(
"
~/test/111.txt
"
),
false
, System.Text.Encoding.Default);
try
{
sw.Write(TextBox1.Text);
sw.Close();
Response.Write(
"
<b>文件写入成功!</b>
"
);
}
catch
{
Response.Write(
"
<b>文件写入失败!</b>
"
);
}
}
}
查看全文
相关阅读:
swift NSComparator
Java mac 上编写Java代码
四舍五入、上取整、下取整
数组排序
删除xcode 里的多余证书
启动画面 设置
CGFloat Float 互转
navigationController pop的几种方法
iOS 获取键盘相关信息
eclipse代码格式化
原文地址:https://www.cnblogs.com/kingfly/p/1584209.html
最新文章
Word文档分割总结
读《浪潮之巅》笔记
『转载』Debussy快速上手(Verdi相似)
windows系统还原
各种仿真波形文件
Vim配置
Vim使用总结
CentOS CVS安装使用
VMware SphereESXi上安装虚拟机
BP神经网络的Java实现(转载)
热门文章
Q-learning简明实例Java代码实现
Q-learning简明实例
mysql执行计划
Java获取配置文件跟路径
Java Callable接口——有返回值的线程
mysql事务(二)——控制语句使用
mysql事务(一)——redo log与undo log
mysql二进制日志
HDFS文件操作
iOS UITableView行高自行扩展
Copyright © 2011-2022 走看看