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>
"
);
}
}
}
查看全文
相关阅读:
美多商城项目(一)
Linux安装Qt
mysql之初体验
Linux系统编程目录
Linux 多线程
进程间通信
Linux进程
Linux文件IO(简易)
Linux常用基本操作
重绘
原文地址:https://www.cnblogs.com/kingfly/p/1584209.html
最新文章
Oracle中文乱码问题
linux常用命令
ADB常用命令
接口测试理论
京东/淘宝的手机销售榜前4名 (android / IOS)
给你一个app你如何展开测试?
发现一个bug如何定位是前端还是后台问题?
你以什么方式来进行对真机的成本降低 ?
ANR----以及如何定位是前端问题还是后台问题?
输入法语音逻辑
热门文章
PC网页端使用体会
linux常用命令
BS4 -->解析库
vue脚手架搭建步骤
爬虫虚拟环境
Scrapy实现多页的爬取
Scrapy框架
DRF 多对多序列化和反序列化
vue 路由拦截器和请求拦截器
django 提供的加密算法
Copyright © 2011-2022 走看看