基础流
装饰器流
包装器类
帮助类
继承自基本的stream流
在基础stream上添加的功能
数据传输
对文件流的操作变简单
基础流
stream
对应的后备存储是文件
内存
网络资源
filestream
memorystream
networkstream
isolatedstorgaefilestream:
继承自filestream
感觉还是挺类java的。
装饰器流
bufferdstream
deflatestream
gzipstream
cryptostream
authenticatedstream
system.io
system.io.compression
system.io.compression
system.security.cryptography
system.net.security
增强缓存
压缩
解压缩
加密解密
安全性
联想装饰者模式,估计是在基本流上面加上一些其他功能,有点儿像对基本类型的功能上的扩展。
包装器类
介绍流的用于数据传输;
textwriter
textreader(定义的一组通用的,读取和写入字符数据的方式)
streamreader
streamwriter:
1,继承自
textwriter
textreader,定义了一组通用的,读取和写入字符数据的方式
2,适用于读取和写入文本字符的场合
binaryreader:用于向流中以二进制的方式写入基元类型
binarywriter:用于从流中读取基元类型
stringreader
stringwriter:
1,也继承自
textwriter
textreader,用于处理字符串
#region stringreader,stringwriter的使用; // string text = @"姓名:水田如雅; // 年龄:20; // 性别:女"; // stringreader reader = new stringreader(text); // int c = reader.read(); // console.writeline((char)c); // char[] buffer = new char[7]; // reader.read(buffer, 0, buffer.length); // console.writeline(string.join("", buffer)); // string line = reader.readline(); // console.write(line); // string rest = reader.readtoend(); // console.writeline(rest); // reader.dispose(); // console.readkey(); #endregion #region streamreader/streamwriter的使用 //filestream fs = new filestream("aboutvac.txt", filemode.open, fileaccess.read); //streamreader reader=new streamreader(fs,encoding.getencoding("gb2312")); //do //{ // console.writeline(reader.readline()); //} while (reader.read()>0); //streamwriter writer = new streamwriter("aboutme.txt", false, encoding.utf8); //writer.write("hello,word"); //reader.dispose(); //writer.dispose(); //console.readkey(); #endregion #region binaryreader/binarywriter的使用 //product product = new product("product.txt") { // id=110, // price=123.3, // name="lhc" //}; //product.save(); //product newitem =new product("product.txt"); //newitem.load(); //console.writeline(newitem); //console.readkey(); #endregion
public class product { public int id { get; set; } public string name { get; set; } public double price { get; set; } private string filepath; public product(string filepath) { this.filepath = filepath; } public void save() { filestream fs = new filestream(this.filepath, filemode.create, fileaccess.write); binarywriter writer = new binarywriter(fs); writer.write(this.id); writer.write(this.name); writer.write(this.price); writer.dispose(); } public void load() { filestream fs = new filestream(this.filepath, filemode.open, fileaccess.read); binaryreader reader = new binaryreader(fs); this.id = reader.readint32(); this.name = reader.readstring(); this.price = reader.readdouble(); reader.dispose(); } public override string tostring() { return string.format("id:{0},name:{1},price:{2}", this.id, this.name, this.price); } }
帮助类
命名空间:system.io
file
fileinfo
path
directory/direcoryinfo
create;
open;
openread;
openwrite;
copy;
处理路径
#region 工具类示例 // file.writealltext("filetest.txt", "hello,i'm using file ", encoding.utf8); #endregion
在使用的时候,还是应该先考虑已有的高级类是否封装了可用的方法,没有的话,再考虑使用基本类进行封装。
以上就是.net 流——流的类型体系简单介绍的内容。
