读书人

C#惯用文件操作总结

发布时间: 2013-03-17 13:48:31 作者: rapoo

C#常用文件操作总结

在C#中,常用的文件操作包含文件的移动,复制,文件的读写,其中文件的读写分为文本文件以及二进制文件。

文本文件与二进制文件有各自的优缺点,文本文件按照字符的ASCII码进行存储,所以你可以直接用记事本打开文本文件,可以看到文件的内容,但是文件的所有的内容在内存中的表示和在记事本中的表示是不一样的,所以读入内存会存在转码的时间消耗,如果你想让文件直观的话,可以采用文本文件。

二进制文件则是直接存储你需要存储内容的在内存中的直接表示,在读取的时候比较快捷,而且二进制文件的大小要比文本文件小很多。


常用的文件操作类是File,File类是一个静态类,所有的成员函数都为静态函数,所以File类的效率比其他的例如FileInfo类的效率要高。一般情况下,File和FileInfo可以实现的功能大同小异。可以根据自己的需要选择不同的类。


File支持文件的基本操作,包括提供了创建、复制、删除、移动、打开以及获取文件的其他的相关属性的一些方法。

同时,为了更好的支持File文件的操作,C#中定义了一个文件流FileStream,可以将文件加载到文件流FileStream中进行更加方便的操作。

为了对FileStream进行操作,C#定义了两组最常用的操作FileStream的类,一组是StreamReader, StreamWriter, 另外一组是BinaryReader, BinaryWriter,。这两组类分别提供了进行文本文件读写以及二进制文件的读取操作。


文件的操作还有一些其他的类,但是对于常用的一些基本的文件操作,有File, FileStream, StreamReader, StreamWriter,BinaryReader, BinaryWriter,这几个类就足够了。


File类的定义,如下所示:


C#惯用文件操作总结C#惯用文件操作总结AppendAllLines(String, IEnumerable<String>)Appends lines to a file, and then closes the file.C#惯用文件操作总结C#惯用文件操作总结AppendAllLines(String, IEnumerable<String>, Encoding)Appends lines to a file by using a specified encoding, and then closes the file.C#惯用文件操作总结C#惯用文件操作总结AppendAllText(String, String)Opens a file, appends the specified string to the file, and then closes the file. If the file does not exist, this method creates a file, writes the specified string to the file, then closes the file.C#惯用文件操作总结C#惯用文件操作总结AppendAllText(String, String, Encoding)Appends the specified string to the file, creating the file if it does not already exist.C#惯用文件操作总结C#惯用文件操作总结C#惯用文件操作总结AppendTextCreates a StreamWriter that appends UTF-8 encoded text to an existing file.C#惯用文件操作总结C#惯用文件操作总结C#惯用文件操作总结Copy(String, String)Copies an existing file to a new file. Overwriting a file of the same name is not allowed.C#惯用文件操作总结C#惯用文件操作总结C#惯用文件操作总结Copy(String, String, Boolean)Copies an existing file to a new file. Overwriting a file of the same name is allowed.C#惯用文件操作总结C#惯用文件操作总结C#惯用文件操作总结Create(String)Creates or overwrites a file in the specified path.C#惯用文件操作总结C#惯用文件操作总结C#惯用文件操作总结Create(String, Int32)Creates or overwrites the specified file.C#惯用文件操作总结C#惯用文件操作总结Create(String, Int32, FileOptions)Creates or overwrites the specified file, specifying a buffer size and a FileOptions value that describes how to create or overwrite the file.C#惯用文件操作总结C#惯用文件操作总结Create(String, Int32, FileOptions, FileSecurity)Creates or overwrites the specified file with the specified buffer size, file options, and file security.C#惯用文件操作总结C#惯用文件操作总结C#惯用文件操作总结CreateTextCreates or opens a file for writing UTF-8 encoded text.C#惯用文件操作总结C#惯用文件操作总结DecryptDecrypts a file that was encrypted by the current account using the Encrypt method.C#惯用文件操作总结C#惯用文件操作总结C#惯用文件操作总结DeleteDeletes the specified file. An exception is not thrown if the specified file does not exist.C#惯用文件操作总结C#惯用文件操作总结EncryptEncrypts a file so that only the account used to encrypt the file can decrypt it.C#惯用文件操作总结C#惯用文件操作总结C#惯用文件操作总结ExistsDetermines whether the specified file exists.C#惯用文件操作总结C#惯用文件操作总结GetAccessControl(String)Gets a FileSecurity object that encapsulates the access control list (ACL) entries for a specified file.C#惯用文件操作总结C#惯用文件操作总结GetAccessControl(String, AccessControlSections)Gets a FileSecurity object that encapsulates the specified type of access control list (ACL) entries for a particular file.C#惯用文件操作总结C#惯用文件操作总结GetAttributesGets the FileAttributes of the file on the path.C#惯用文件操作总结C#惯用文件操作总结C#惯用文件操作总结GetCreationTimeReturns the creation date and time of the specified file or directory.C#惯用文件操作总结C#惯用文件操作总结GetCreationTimeUtcReturns the creation date and time, in coordinated universal time (UTC), of the specified file or directory.C#惯用文件操作总结C#惯用文件操作总结C#惯用文件操作总结GetLastAccessTimeReturns the date and time the specified file or directory was last accessed.C#惯用文件操作总结C#惯用文件操作总结GetLastAccessTimeUtcReturns the date and time, in coordinated universal time (UTC), that the specified file or directory was last accessed.C#惯用文件操作总结C#惯用文件操作总结C#惯用文件操作总结GetLastWriteTimeReturns the date and time the specified file or directory was last written to.C#惯用文件操作总结C#惯用文件操作总结GetLastWriteTimeUtcReturns the date and time, in coordinated universal time (UTC), that the specified file or directory was last written to.C#惯用文件操作总结C#惯用文件操作总结C#惯用文件操作总结MoveMoves a specified file to a new location, providing the option to specify a new file name.C#惯用文件操作总结C#惯用文件操作总结C#惯用文件操作总结Open(String, FileMode)Opens a FileStream on the specified path with read/write access.C#惯用文件操作总结C#惯用文件操作总结C#惯用文件操作总结Open(String, FileMode, FileAccess)Opens a FileStream on the specified path, with the specified mode and access.C#惯用文件操作总结C#惯用文件操作总结C#惯用文件操作总结Open(String, FileMode, FileAccess, FileShare)Opens a FileStream on the specified path, having the specified mode with read, write, or read/write access and the specified sharing option.C#惯用文件操作总结C#惯用文件操作总结C#惯用文件操作总结OpenReadOpens an existing file for reading.C#惯用文件操作总结C#惯用文件操作总结C#惯用文件操作总结OpenTextOpens an existing UTF-8 encoded text file for reading.C#惯用文件操作总结C#惯用文件操作总结C#惯用文件操作总结OpenWriteOpens an existing file or creates a new file for writing.C#惯用文件操作总结C#惯用文件操作总结ReadAllBytesOpens a binary file, reads the contents of the file into a byte array, and then closes the file.C#惯用文件操作总结C#惯用文件操作总结ReadAllLines(String)Opens a text file, reads all lines of the file, and then closes the file.C#惯用文件操作总结C#惯用文件操作总结ReadAllLines(String, Encoding)Opens a file, reads all lines of the file with the specified encoding, and then closes the file.C#惯用文件操作总结C#惯用文件操作总结ReadAllText(String)Opens a text file, reads all lines of the file, and then closes the file.C#惯用文件操作总结C#惯用文件操作总结ReadAllText(String, Encoding)Opens a file, reads all lines of the file with the specified encoding, and then closes the file.C#惯用文件操作总结C#惯用文件操作总结ReadLines(String)Reads the lines of a file.C#惯用文件操作总结C#惯用文件操作总结ReadLines(String, Encoding)Read the lines of a file that has a specified encoding.C#惯用文件操作总结C#惯用文件操作总结Replace(String, String, String)Replaces the contents of a specified file with the contents of another file, deleting the original file, and creating a backup of the replaced file.C#惯用文件操作总结C#惯用文件操作总结Replace(String, String, String, Boolean)Replaces the contents of a specified file with the contents of another file, deleting the original file, and creating a backup of the replaced file and optionally ignores merge errors.C#惯用文件操作总结C#惯用文件操作总结SetAccessControlApplies access control list (ACL) entries described by a FileSecurity object to the specified file.C#惯用文件操作总结C#惯用文件操作总结SetAttributesSets the specified FileAttributes of the file on the specified path.C#惯用文件操作总结C#惯用文件操作总结SetCreationTimeSets the date and time the file was created.C#惯用文件操作总结C#惯用文件操作总结SetCreationTimeUtcSets the date and time, in coordinated universal time (UTC), that the file was created.C#惯用文件操作总结C#惯用文件操作总结SetLastAccessTimeSets the date and time the specified file was last accessed.C#惯用文件操作总结C#惯用文件操作总结SetLastAccessTimeUtcSets the date and time, in coordinated universal time (UTC), that the specified file was last accessed.C#惯用文件操作总结C#惯用文件操作总结SetLastWriteTimeSets the date and time that the specified file was last written to.C#惯用文件操作总结C#惯用文件操作总结SetLastWriteTimeUtcSets the date and time, in coordinated universal time (UTC), that the specified file was last written to.C#惯用文件操作总结C#惯用文件操作总结WriteAllBytesCreates a new file, writes the specified byte array to the file, and then closes the file. If the target file already exists, it is overwritten.C#惯用文件操作总结C#惯用文件操作总结WriteAllLines(String, IEnumerable<String>)Creates a new file, writes a collection of strings to the file, and then closes the file.C#惯用文件操作总结C#惯用文件操作总结WriteAllLines(String,String[])Creates a new file, write the specified string array to the file, and then closes the file.C#惯用文件操作总结C#惯用文件操作总结WriteAllLines(String, IEnumerable<String>, Encoding)Creates a new file by using the specified encoding, writes a collection of strings to the file, and then closes the file.C#惯用文件操作总结C#惯用文件操作总结WriteAllLines(String,String[], Encoding) Creates a new file, writes the specified string array to the file by using the specified encoding, and then closes the file.C#惯用文件操作总结C#惯用文件操作总结WriteAllText(String, String)Creates a new file, writes the specified string to the file, and then closes the file. If the target file already exists, it is overwritten.C#惯用文件操作总结C#惯用文件操作总结WriteAllText(String, String, Encoding)Creates a new file, writes the specified string to the file using the specified encoding, and then closes the file. If the target file already exists, it is overwritten.Top

然后在看看我们的FileStream类的成员:


C#惯用文件操作总结FileStream(IntPtr, FileAccess)Obsolete. Initializes a new instance of the FileStream class for the specified file handle, with the specified read/write permission.C#惯用文件操作总结FileStream(SafeFileHandle, FileAccess)Initializes a new instance of the FileStream class for the specified file handle, with the specified read/write permission.C#惯用文件操作总结C#惯用文件操作总结FileStream(String, FileMode)Initializes a new instance of the FileStream class with the specified path and creation mode.C#惯用文件操作总结FileStream(IntPtr, FileAccess, Boolean)Obsolete. Initializes a new instance of the FileStream class for the specified file handle, with the specified read/write permission andFileStream(SafeFileHandle, FileAccess, Int32)Initializes a new instance of the FileStream class for the specified file handle, with the specified read/write permission, and buffer size.C#惯用文件操作总结C#惯用文件操作总结FileStream(String, FileMode, FileAccess)Initializes a new instance of the FileStream class with the specified path, creation mode, and read/write permission.C#惯用文件操作总结FileStream(IntPtr, FileAccess, Boolean, Int32)Obsolete. Initializes a new instance of the FileStream class for the specified file handle, with the specified read/write permission,FileStream(SafeFileHandle, FileAccess, Int32, Boolean)Initializes a new instance of the FileStream class for the specified file handle, with the specified read/write permission, buffer size, and synchronous or asynchronous state.C#惯用文件操作总结C#惯用文件操作总结FileStream(String, FileMode, FileAccess, FileShare)Initializes a new instance of the FileStream class with the specified path, creation mode, read/write permission, and sharing permission.C#惯用文件操作总结FileStream(IntPtr, FileAccess, Boolean, Int32, Boolean)Obsolete. Initializes a new instance of the FileStream class for the specified file handle, with the specified read/write permission,C#惯用文件操作总结FileStream(String, FileMode, FileAccess, FileShare, Int32)Initializes a new instance of the FileStream class with the specified path, creation mode, read/write and sharing permission, and buffer size.C#惯用文件操作总结C#惯用文件操作总结FileStream(String, FileMode, FileAccess, FileShare, Int32, Boolean)Initializes a new instance of the FileStream class with the specified path, creation mode, read/write and sharing permission, buffer size, and synchronous or asynchronous state.C#惯用文件操作总结FileStream(String, FileMode, FileAccess, FileShare, Int32, FileOptions)Initializes a new instance of the FileStream class with the specified path, creation mode, read/write and sharing permission, the access other FileStreams can have to the same file, the buffer size, and additional file options.C#惯用文件操作总结FileStream(String, FileMode, FileSystemRights, FileShare, Int32, FileOptions)Initializes a new instance of the FileStream class with the specified path, creation mode, access rights and sharing permission, the buffer size, and additional file options.C#惯用文件操作总结FileStream(String, FileMode, FileSystemRights, FileShare, Int32, FileOptions, FileSecurity)Initializes a new instance of the FileStream class with the specified path, creation mode, access rights and sharing permission, the buffer size, additional file options, access control and audit security.TopC#惯用文件操作总结BeginReadBegins an asynchronous read. (Overrides Stream.BeginRead(Byte[], Int32, Int32, AsyncCallback, Object).)

In XNA Framework 3.0, this member is inherited from Stream.BeginRead(Byte[], Int32, Int32, AsyncCallback, Object) .C#惯用文件操作总结C#惯用文件操作总结BeginReadBegins an asynchronous read operation. (Inherited from Stream.)C#惯用文件操作总结C#惯用文件操作总结BeginWriteBegins an asynchronous write. (Overrides Stream.BeginWrite(Byte[], Int32, Int32, AsyncCallback, Object).)

In XNA Framework 3.0, this member is inherited from Stream.BeginWrite(Byte[], Int32, Int32, AsyncCallback, Object) .C#惯用文件操作总结C#惯用文件操作总结BeginWriteBegins an asynchronous write operation. (Inherited from Stream.)C#惯用文件操作总结C#惯用文件操作总结CloseCloses the current stream and releases any resources (such as sockets and file handles) associated with the current stream. (Inherited fromStream.)C#惯用文件操作总结CopyTo(Stream)Reads all the bytes from the current stream and writes them to the destination stream. (Inherited fromStream.)C#惯用文件操作总结CopyTo(Stream, Int32)Reads all the bytes from the current stream and writes them to a destination stream, using a specified buffer size. (Inherited fromStream.)C#惯用文件操作总结CreateObjRefCreates an object that contains all the relevant information required to generate a proxy used to communicate with a remote object. (Inherited fromMarshalByRefObject.)C#惯用文件操作总结C#惯用文件操作总结CreateWaitHandleObsolete. Allocates a WaitHandle object. (Inherited from Stream.)C#惯用文件操作总结C#惯用文件操作总结Dispose()Infrastructure. Releases all resources used by the Stream. (Inherited from Stream.)C#惯用文件操作总结C#惯用文件操作总结Dispose(Boolean)Releases the unmanaged resources used by the FileStream and optionally releases the managed resources. (Overrides Stream.Dispose(Boolean) .)C#惯用文件操作总结C#惯用文件操作总结EndReadWaits for the pending asynchronous read to complete. (Overrides Stream.EndRead(IAsyncResult) .)

In XNA Framework 3.0, this member is inherited from Stream.EndRead(IAsyncResult).C#惯用文件操作总结C#惯用文件操作总结EndReadWaits for the pending asynchronous read to complete. (Inherited from Stream.)C#惯用文件操作总结C#惯用文件操作总结EndWriteEnds an asynchronous write, blocking until the I/O operation has completed. (OverridesStream.EndWrite(IAsyncResult) .)

In XNA Framework 3.0, this member is inherited from Stream.EndWrite(IAsyncResult).C#惯用文件操作总结C#惯用文件操作总结EndWriteEnds an asynchronous write operation. (Inherited from Stream.)C#惯用文件操作总结C#惯用文件操作总结Equals(Object)Determines whether the specified Object is equal to the current Object. (Inherited from Object.)C#惯用文件操作总结C#惯用文件操作总结FinalizeEnsures that resources are freed and other cleanup operations are performed when the garbage collector reclaims theC#惯用文件操作总结Flush()Clears buffers for this stream and causes any buffered data to be written to the file. (OverridesStream.Flush().)C#惯用文件操作总结Flush(Boolean)Clears buffers for this stream and causes any buffered data to be written to the file, and also clears all intermediate file buffers.C#惯用文件操作总结GetAccessControlGets a FileSecurity object that encapsulates the access control list (ACL) entries for the file described by the currentFileStream object.C#惯用文件操作总结C#惯用文件操作总结GetHashCodeServes as a hash function for a particular type. (Inherited from Object.)C#惯用文件操作总结GetLifetimeServiceRetrieves the current lifetime service object that controls the lifetime policy for this instance. (Inherited fromMarshalByRefObject.)C#惯用文件操作总结C#惯用文件操作总结GetTypeGets the Type of the current instance. (Inherited from Object.)C#惯用文件操作总结InitializeLifetimeServiceObtains a lifetime service object to control the lifetime policy for this instance. (Inherited fromMarshalByRefObject.)C#惯用文件操作总结LockPrevents other processes from reading from or writing to the FileStream.C#惯用文件操作总结C#惯用文件操作总结MemberwiseCloneCreates a shallow copy of the current Object. (Inherited from Object.)C#惯用文件操作总结MemberwiseClone(Boolean)Creates a shallow copy of the current MarshalByRefObject object. (Inherited from MarshalByRefObject.)C#惯用文件操作总结ObjectInvariantInfrastructure. Provides support for a Contract. (Inherited from Stream.)C#惯用文件操作总结C#惯用文件操作总结ReadReads a block of bytes from the stream and writes the data in a given buffer. (OverridesStream.Read(Byte[], Int32, Int32).)C#惯用文件操作总结C#惯用文件操作总结ReadByteReads a byte from the file and advances the read position one byte. (OverridesStream.ReadByte().)C#惯用文件操作总结C#惯用文件操作总结SeekSets the current position of this stream to the given value. (Overrides Stream.Seek(Int64, SeekOrigin) .)C#惯用文件操作总结SetAccessControlApplies access control list (ACL) entries described by a FileSecurity object to the file described by the current FileStream object.C#惯用文件操作总结C#惯用文件操作总结SetLengthSets the length of this stream to the given value. (Overrides Stream.SetLength(Int64) .)C#惯用文件操作总结C#惯用文件操作总结ToStringReturns a String that represents the current Object. (Inherited from Object.)C#惯用文件操作总结UnlockAllows access by other processes to all or part of a file that was previously locked.C#惯用文件操作总结C#惯用文件操作总结WriteWrites a block of bytes to this stream using data from a buffer. (Overrides Stream.Write(Byte[], Int32, Int32).)C#惯用文件操作总结C#惯用文件操作总结WriteByteWrites a byte to the current position in the file stream. (Overrides Stream.WriteByte(Byte) .)TopC#惯用文件操作总结CanReadGets a value indicating whether the current stream supports reading. (OverridesStream.CanRead .)C#惯用文件操作总结C#惯用文件操作总结CanSeekGets a value indicating whether the current stream supports seeking. (OverridesStream.CanSeek .)C#惯用文件操作总结C#惯用文件操作总结CanTimeoutGets a value that determines whether the current stream can time out. (Inherited fromStream.)C#惯用文件操作总结C#惯用文件操作总结CanWriteGets a value indicating whether the current stream supports writing. (OverridesStream.CanWrite .)C#惯用文件操作总结HandleObsolete. Gets the operating system file handle for the file that the currentC#惯用文件操作总结IsAsyncGets a value indicating whether the C#惯用文件操作总结LengthGets the length in bytes of the stream. (Overrides Stream.Length .)C#惯用文件操作总结C#惯用文件操作总结NameGets the name of the C#惯用文件操作总结PositionGets or sets the current position of this stream. (Overrides Stream.Position .)C#惯用文件操作总结C#惯用文件操作总结ReadTimeoutGets or sets a value, in miliseconds, that determines how long the stream will attempt to read before timing out. (Inherited fromStream.)C#惯用文件操作总结SafeFileHandleGets a SafeFileHandle object that represents the operating system file handle for the file that the currentFileStream object encapsulates.C#惯用文件操作总结C#惯用文件操作总结WriteTimeoutGets or sets a value, in miliseconds, that determines how long the stream will attempt to write before timing out. (Inherited fromStream.)Top


可以看到都是对字节流的操作,这种对于字节流的操作,对于大部分来说还是比较困难的,所以c#又帮助我们封装了对FileStream的操作,那就是StreamReader, StreamWriter, BinaryReader, BinaryWriter.

下面分别看看这两组类怎么使用:

StreamReader, StreamWriter


C#惯用文件操作总结C#惯用文件操作总结StreamReader(Stream)Initializes a new instance of the StreamReader class for the specified stream.C#惯用文件操作总结C#惯用文件操作总结StreamReader(String)Initializes a new instance of the StreamReader class for the specified file name.C#惯用文件操作总结C#惯用文件操作总结StreamReader(Stream, Boolean)Initializes a new instance of the StreamReader class for the specified stream, with the specified byte order mark detection option.C#惯用文件操作总结C#惯用文件操作总结StreamReader(Stream, Encoding)Initializes a new instance of the StreamReader class for the specified stream, with the specified character encoding.C#惯用文件操作总结C#惯用文件操作总结StreamReader(String, Boolean)Initializes a new instance of the StreamReader class for the specified file name, with the specified byte order mark detection option.C#惯用文件操作总结C#惯用文件操作总结StreamReader(String, Encoding)Initializes a new instance of the StreamReader class for the specified file name, with the specified character encoding.C#惯用文件操作总结C#惯用文件操作总结StreamReader(Stream, Encoding, Boolean)Initializes a new instance of the StreamReader class for the specified stream, with the specified character encoding and byte order mark detection option.C#惯用文件操作总结C#惯用文件操作总结StreamReader(String, Encoding, Boolean)Initializes a new instance of the StreamReader class for the specified file name, with the specified character encoding and byte order mark detection option.C#惯用文件操作总结C#惯用文件操作总结StreamReader(Stream, Encoding, Boolean, Int32)Initializes a new instance of the StreamReader class for the specified stream, with the specified character encoding, byte order mark detection option, and buffer size.C#惯用文件操作总结C#惯用文件操作总结StreamReader(String, Encoding, Boolean, Int32)Initializes a new instance of the StreamReader class for the specified file name, with the specified character encoding, byte order mark detection option, and buffer size.TopC#惯用文件操作总结CloseCloses the StreamReader object and the underlying stream, and releases any system resources associated with the reader. (OverridesTextReader.Close().)C#惯用文件操作总结CreateObjRefCreates an object that contains all the relevant information required to generate a proxy used to communicate with a remote object. (Inherited fromMarshalByRefObject.)C#惯用文件操作总结C#惯用文件操作总结DiscardBufferedDataAllows a StreamReader object to discard its current data.C#惯用文件操作总结C#惯用文件操作总结Dispose()Releases all resources used by the TextReader object. (Inherited from TextReader.)C#惯用文件操作总结C#惯用文件操作总结Dispose(Boolean)Closes the underlying stream, releases the unmanaged resources used by the StreamReader, and optionally releases the managed resources. (Overrides TextReader.Dispose(Boolean) .)C#惯用文件操作总结C#惯用文件操作总结Equals(Object)Determines whether the specified Object is equal to the current Object. (Inherited from Object.)C#惯用文件操作总结C#惯用文件操作总结FinalizeAllows an Object to attempt to free resources and perform other cleanup operations before theObject is reclaimed by garbage collection. (Inherited from Object.)C#惯用文件操作总结C#惯用文件操作总结GetHashCodeServes as a hash function for a particular type. (Inherited from Object.)C#惯用文件操作总结GetLifetimeServiceRetrieves the current lifetime service object that controls the lifetime policy for this instance. (Inherited fromMarshalByRefObject.)C#惯用文件操作总结C#惯用文件操作总结GetTypeGets the Type of the current instance. (Inherited from Object.)C#惯用文件操作总结InitializeLifetimeServiceObtains a lifetime service object to control the lifetime policy for this instance. (Inherited fromMarshalByRefObject.)C#惯用文件操作总结C#惯用文件操作总结MemberwiseCloneCreates a shallow copy of the current Object. (Inherited from Object.)C#惯用文件操作总结MemberwiseClone(Boolean)Creates a shallow copy of the current MarshalByRefObject object. (Inherited from MarshalByRefObject.)C#惯用文件操作总结C#惯用文件操作总结PeekReturns the next available character but does not consume it. (Overrides TextReader.Peek().)C#惯用文件操作总结C#惯用文件操作总结Read()Reads the next character from the input stream and advances the character position by one character. (OverridesTextReader.Read().)C#惯用文件操作总结C#惯用文件操作总结Read(Char[], Int32, Int32) Reads a maximum of C#惯用文件操作总结ReadBlockReads a maximum of C#惯用文件操作总结ReadLineReads a line of characters from the current stream and returns the data as a string. (OverridesTextReader.ReadLine().)C#惯用文件操作总结C#惯用文件操作总结ReadToEndReads the stream from the current position to the end of the stream. (OverridesTextReader.ReadToEnd().)C#惯用文件操作总结C#惯用文件操作总结ToStringReturns a String that represents the current Object. (Inherited from Object.)Top

C#惯用文件操作总结C#惯用文件操作总结BinaryReader(Stream)Initializes a new instance of the BinaryReader class based on the supplied stream and using UTF8Encoding.C#惯用文件操作总结C#惯用文件操作总结BinaryReader(Stream, Encoding)Initializes a new instance of the BinaryReader class based on the supplied stream and a specific character encoding.TopC#惯用文件操作总结CloseCloses the current reader and the underlying stream.C#惯用文件操作总结Dispose()Releases all resources used by the current instance of the BinaryReader class.C#惯用文件操作总结C#惯用文件操作总结Dispose(Boolean)Releases the unmanaged resources used by the BinaryReader class and optionally releases the managed resources.C#惯用文件操作总结C#惯用文件操作总结Equals(Object)Determines whether the specified Object is equal to the current Object. (Inherited from Object.)C#惯用文件操作总结C#惯用文件操作总结FillBufferFills the internal buffer with the specified number of bytes read from the stream.C#惯用文件操作总结C#惯用文件操作总结FinalizeAllows an Object to attempt to free resources and perform other cleanup operations before theObject is reclaimed by garbage collection. (Inherited from Object.)C#惯用文件操作总结C#惯用文件操作总结GetHashCodeServes as a hash function for a particular type. (Inherited from Object.)C#惯用文件操作总结C#惯用文件操作总结GetTypeGets the Type of the current instance. (Inherited from Object.)C#惯用文件操作总结C#惯用文件操作总结MemberwiseCloneCreates a shallow copy of the current Object. (Inherited from Object.)C#惯用文件操作总结C#惯用文件操作总结PeekCharReturns the next available character and does not advance the byte or character position.C#惯用文件操作总结C#惯用文件操作总结Read()Reads characters from the underlying stream and advances the current position of the stream in accordance with theC#惯用文件操作总结Read(Byte[], Int32, Int32) Reads the specified number of bytes from the stream, starting from a specified point in the byte array.C#惯用文件操作总结C#惯用文件操作总结Read(Char[], Int32, Int32) Reads the specified number of characters from the stream, starting from a specified point in the character array.C#惯用文件操作总结C#惯用文件操作总结Read7BitEncodedIntReads in a 32-bit integer in compressed format.C#惯用文件操作总结C#惯用文件操作总结ReadBooleanReads a C#惯用文件操作总结ReadByteReads the next byte from the current stream and advances the current position of the stream by one byte.C#惯用文件操作总结C#惯用文件操作总结ReadBytesReads the specified number of bytes from the current stream into a byte array and advances the current position by that number of bytes.C#惯用文件操作总结C#惯用文件操作总结ReadCharReads the next character from the current stream and advances the current position of the stream in accordance with theC#惯用文件操作总结ReadCharsReads the specified number of characters from the current stream, returns the data in a character array, and advances the current position in accordance with theC#惯用文件操作总结ReadDecimalReads a decimal value from the current stream and advances the current position of the stream by sixteen bytes.C#惯用文件操作总结C#惯用文件操作总结ReadDoubleReads an 8-byte floating point value from the current stream and advances the current position of the stream by eight bytes.C#惯用文件操作总结C#惯用文件操作总结ReadInt16Reads a 2-byte signed integer from the current stream and advances the current position of the stream by two bytes.C#惯用文件操作总结C#惯用文件操作总结ReadInt32Reads a 4-byte signed integer from the current stream and advances the current position of the stream by four bytes.C#惯用文件操作总结C#惯用文件操作总结ReadInt64Reads an 8-byte signed integer from the current stream and advances the current position of the stream by eight bytes.C#惯用文件操作总结C#惯用文件操作总结ReadSByteReads a signed byte from this stream and advances the current position of the stream by one byte.C#惯用文件操作总结C#惯用文件操作总结ReadSingleReads a 4-byte floating point value from the current stream and advances the current position of the stream by four bytes.C#惯用文件操作总结C#惯用文件操作总结ReadStringReads a string from the current stream. The string is prefixed with the length, encoded as an integer seven bits at a time.C#惯用文件操作总结C#惯用文件操作总结ReadUInt16Reads a 2-byte unsigned integer from the current stream using little-endian encoding and advances the position of the stream by two bytes.C#惯用文件操作总结C#惯用文件操作总结ReadUInt32Reads a 4-byte unsigned integer from the current stream and advances the position of the stream by four bytes.C#惯用文件操作总结C#惯用文件操作总结ReadUInt64Reads an 8-byte unsigned integer from the current stream and advances the position of the stream by eight bytes.C#惯用文件操作总结C#惯用文件操作总结ToStringReturns a String that represents the current Object. (Inherited from Object.)Top

读书人网 >C#

热点推荐