文件操作类,方法


-> windows环境下文本文件基本格式
-> 字符集的历史:ascii->双字节->unicode(utf-16)->utf-8

  1. -> ANSI
  2. -> unicode
  3. -> unicode big endim
  4. -> utf-8


-> 类
-> 命名空间:System.IO; // input output
-> FileStream 文件流 将文件以字节的方式进行读写
-> 构造方法:new FileStream(文件路径, FileMode, FileAccess);

  1. FileMode:Create、Append、Open

-> 读写方法:

  1. int ReadByte(); void WriteByte(byte);
  2.  int Read(byte[] buffer, int offset, int count);
  3. void Write(byte[] buffer, int offset, int count);

-> 了解

  1. -> void Flush(); // 清空缓存,写入硬盘
  2. -> void Dispose(); // 清空非托管资源
  3. -> Position属性 // 文件处理,指针与文本文件书写一样是有位置的

-> StreamReader与StreamWriter 专门针对文本文件的读写操作
-> 读流:
new StreamReader("文件路径", Encoding);
-> 写流
new StreamWriter("文件路径", bool isAppend, Encoding);
-> 读的方法
string ReadLine(); // 读取文件中的一行
string ReadToEnd(); // 读取所有的内容
-> 写的方法
void Write(...); // 写入内容
void WriteLine(...); // 写入一行文本
-> File 静态
AppendAllText
AppendAllLines
ReadAllText
ReadAllLines
WriteAllText
WriteAllLines
bool Exist()
-> Directory 静态
string[] GetFiles(string) // 返回指定路径下的所有文件
string[] GetDirectories(string) // 返回改路径下的所有子文件夹
bool Exist()
-> Path 处理路径
获得后缀名
获得文件名
获得没有后缀名的文件名
获得全路径
-> FileInfo DirectoryInfo DriverInfo

转载于:https://www.cnblogs.com/kakakade/p/4906619.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值