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>
"
);
}
}
}
查看全文
相关阅读:
IO学习BufferedWriter 规格严格
Finalization 规格严格
linux下查看主板内存槽与内存信息 规格严格
调试JavaScript/VB Script脚本程序(Wscript篇) 规格严格
ORA01688:unable to extend table name。name partition NAME by NUM in tablespace NAME 规格严格
Hidden Java 7 Features – SecondaryLoop 规格严格
Web应用服务器监控 规格严格
NetBeans 时事通讯(刊号 # 12 Jun 16, 2008)
NetBeans 时事通讯(刊号 # 12 Jun 16, 2008)
Win32 DLL的一个调试心得
原文地址:https://www.cnblogs.com/kingfly/p/1584209.html
最新文章
nodejs 异步之 Timer &Tick; 篇
node chat源码解读(三)程序即server
获得本机IP
谁是谁的妈, 谁是谁的爸
Linpack的安装部署
zoj 3296 Mancher 算法 + 最小区间覆盖
10716 Evil Straw Warts Live
[Win8]Windows8开发笔记(七):页面样式的相关介绍
webview中cookie的读取与保存
安卓开发之多个TextView跑马灯
热门文章
(续)SqlHelper+三层架构 +例子1)复习创建客户和三层的知识+、(例子2)项目初始框架(HRMSys)
2012年百度校园实习招聘题目及解答(一)
如何使得VC++6.0时刻显示行号
用thinkphp开启伪静态,用wamp开启很快搞定;但是用phpstudy总是开启失败,为什么?...
两种方法上传本地文件到github
XWindows桌面
window下phpstudy的nginx配置虚拟主机
一个有趣的VBS 规格严格
SNMP4J MIB Parse 规格严格
The Mystery Of Multiple MBeanServers 规格严格
Copyright © 2011-2022 走看看