码迷,mamicode.com
首页 > 其他好文 > 详细

文件操作类,方法

时间:2015-10-24 14:12:48      阅读:167      评论:0      收藏:0      [点我收藏+]

标签:


-> 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

文件操作类,方法

标签:

原文地址:http://www.cnblogs.com/kakakade/p/4906619.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!