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 TCP/IP 连接查看和问题解决
Linux Tomcat 7.0 管理员登录时"401 Unauthorized" 问题解决方法
Tomcat 性能监控工具jvisualvm, JConsole
Tomcat 实战-调优方案
Linux Tomcat8 访问管理页面 403 Access Denied
docker redis
Spring Boot 定时任务
Nginx rewrite使用
五 python 发送邮件
关于注解继承性的一个例子
原文地址:https://www.cnblogs.com/kingfly/p/1584209.html
最新文章
记录一次出差广东对中间件性能优化的完整报告
深入理解计算机系统之旅(二)信息在计算机中的表示和处理
cocos2d-x CCControl控件
HDU 4824 Disk Schedule
Linux改动hostname的两个办法
Apache网站服务器配置
Linux命令详解-用户管理
Linux命令详解-ftp服务器配置
linux nohup screen注解
windows刷新dns命令
热门文章
linux {..}用法
mysql 主键与外键
zabbix3.4+grafana5.0.1数据可视化
Mysql 查看用户
mysql 账号授权
powerDesigner
Linux 查看盘结构命令
Linux 安装操作系统标准
Android bitmap转byte
Android 获取图片转bitmap
Copyright © 2011-2022 走看看