最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
asp.net c#创建的数据文件进行读取
时间:2022-06-25 05:04:27 编辑:袖梨 来源:一聚教程网
asp教程.net c#创建的数据文件进行读取
using system;
using system.web;public class averagehandler : ihttphandler
{
public bool isreusable
{ get { return true; } }
public void processrequest(httpcontext ctx)
{
ctx.response.write("hello");
}
}
cs文件
using system.web
public sealed class textbuilder : ihttphandler
{
public void processrequest(httpcontext context)
{
context.response.clearcontent();
context.response.contenttype = "text/plain";
context.response.write("hello world");
context.response.end();
}
public bool isreusable
{
get { return true; }
}
}
方法二
binarywriter 和 binaryreader 类用于读取和写入数据,而不是字符串。下面的代码示例示范了向新的、空文件流 (test.data) 写入数据及从该文件读取数据。在当前目录中创建了数据文件之后,也就同时创建了相关的 binarywriter 和 binaryreader,binarywriter 用于向 test.data 写入整数 0 到 10,test.data 在文件尾留下了一个文件指针。在将文件指针设置回初始位置后,binaryreader 读出指定的内容。
[c#]
using system;
using system.io;
class mystream {
private const string file_name = "test.data";
public static void main(string[] args) {
// create the new, empty data file.
if (file.exists(file_name)) {
console.writeline("{0} already exists!", file_name);
return;
}
filestream fs = new filestream(file_name, filemode.createnew);
// create the writer for data.
binarywriter w = new binarywriter(fs);
// write data to test.data.
for (int i = 0; i w.write( (int) i);
}
w.close();
fs.close();
// create the reader for data.
fs = new filestream(file_name, filemode.open, fileaccess.read);
binaryreader r = new binaryreader(fs);
// read data from test.data.
for (int i = 0; i console.writeline(r.readint32());
w.close();
}
}
}
如果 test.data 已存在于当前目录中,则引发一个 ioexception。始终使用 filemode.create 创建新文件,而不引发 ioexception。
方法四
using system.web
public sealed class textbuilder : ihttphandler
{
public void processrequest(httpcontext context)
{
context.response.clearcontent();
context.response.contenttype = "text/plain";
context.response.write("hello world");
context.response.end();
}
public bool isreusable
{
get { return true; }
}
}
相关文章
- 二重螺旋奉香群英试 二重螺旋奉香群英试详细玩法攻略与通关技巧 07-07
- 《背包英雄》钱包英雄成就解锁指南 07-07
- 寻梦丝路炼金师和锻造师选择建议 07-07
- 萌宅社区app如何找回密码 07-07
- 《红色沙漠》黄金商人成就做法分享 07-07
- 宠物集结上线时间是什么时候 宠物集结手游正式开服日期及预约入口 07-07