现在的位置: 首页 > 综合 > 正文

C# 文件操作必须要掌握的几个类(一)

2013年02月26日 ⁄ 综合 ⁄ 共 1456字 ⁄ 字号 评论关闭

BinaryReader类——从文件流中读取二进制文件

构造函数:BinaryReader() 重载,实例化一个BinaryReader对象

方法:

   Close(),关闭当前reader和潜在的流

   Dispose(),释放被BinaryReader使用的未托管的资源,并选择性的释放托管资源

   Equals(),判断指定对象是否和当前对象相等

   FillBuffer(),用一个从流中读取的制定数量的字节来填充内在缓冲区

   Finalize(), 在对象被回收机制回收资源之前,允许该对象尝试释放资源和执行其他清除操作

   GetHashCode(), 作为一个hash函数为制定类型提供服务

   GetType(), 得到当前实例的类型

   MemberwiseClone(), 为当前对象创建一个浅拷贝

   PeekChar(), 返回下一个可用的字符,并且不前景字符或字节的位置

   Read(), 重载,从潜在的流中读取字符,并且移动当前流的位置

属性:BaseStream  访问潜在二进制流

 

BinaryWriter类——将二进制流写入文件中

Reader类相似,方法稍微少了点。

 

用法:

一般都是先用FileStream定义一个文件流对象,然后再用BinaryReaderBinaryWriter对文件进行读写。


Directory

  Exposes static methods for creating, moving, and enumerating through directories and subdirectories. This class cannot be inherited.

  提供一些静态方法来创建,移动 并且列举目录和子目录。类不能够被继承。


File

  Provides static methods for the creation, copying, deletion, moving, and opening of files, and aids in the creation of FileStream objects.

  提供一系列静态方法来创建、拷贝、删除、移动和打开创建的文件,并且帮助文件流对象的创建。

 

DirectoryInfo

  Exposes instance methods for creating, moving, and enumerating through directories and subdirectories. This class cannot be inherited.

  提供实例化方法来创建,移动,列举目录和子目录,该类不能被继承。

基本的方法:

Create(),

CreateSubdirectory(),

Move(),

GetDirectories(),

GetFiles(),

 

FileInfo

Provides instance methods for the creation, copying, deletion, moving, and opening of files, and aids in the creation of FileStream objects. This class cannot be inherited.

提供一些实例化方法来创建,拷贝,删除,移动和打开文件,并且为文件流的创建提供帮助。不能够被继承。

基本的方法:

Create(),

Delete(),

Copy(),

Open(),

Move()

抱歉!评论已关闭.