FileStream Class

[This documentation is for preview only, and is subject to change in later releases. Blank topics are included as placeholders.]

Exposes a Stream around a file, supporting both synchronous and asynchronous read and write operations.

Namespace:  System.IO
Assembly:  System.IO (in System.IO.dll)

'Declaration
Public Class FileStream _
	Inherits Stream

The FileStream type exposes the following members.

  NameDescription
Public methodFileStream(String, FileMode)Initializes a new instance of the FileStream class with the specified path and creation mode.
Public methodFileStream(String, FileMode, FileAccess)Initializes a new instance of the FileStream class with the specified path, creation mode, and read/write permission.
Public methodFileStream(String, FileMode, FileAccess, FileShare)Initializes a new instance of the FileStream class with the specified path, creation mode, read/write permission, and sharing permission.
Public methodFileStream(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.
Top

  NameDescription
Public propertyCanReadGets a value indicating whether the current stream supports reading. (Overrides Stream..::..CanRead.)
Public propertyCanSeekGets a value indicating whether the current stream supports seeking. (Overrides Stream..::..CanSeek.)
Public propertyCanTimeoutGets a value that determines whether the current stream can time out. (Inherited from Stream.)
Public propertyCanWriteGets a value indicating whether the current stream supports writing. (Overrides Stream..::..CanWrite.)
Public propertyIsAsyncGets a value indicating whether the FileStream was opened asynchronously or synchronously.
Public propertyLengthGets the length in bytes of the stream. (Overrides Stream..::..Length.)
Public propertyNameGets the name of the FileStream that was passed to the constructor.
Public propertyPositionGets or sets the current position of this stream. (Overrides Stream..::..Position.)
Public propertyReadTimeoutGets or sets a value, in milliseconds, that determines how long the stream will attempt to read before timing out. (Inherited from Stream.)
Public propertyWriteTimeoutGets or sets a value, in miliseconds, that determines how long the stream will attempt to write before timing out. (Inherited from Stream.)
Top

  NameDescription
Public methodCloseCloses the current stream and releases any resources (such as sockets and file handles) associated with the current stream. Instead of calling this method, ensure that the stream is properly disposed. (Inherited from Stream.)
Public methodDispose()()()()Releases all resources used by the Stream. (Inherited from Stream.)
Protected methodDispose(Boolean)Releases the unmanaged resources used by the FileStream and optionally releases the managed resources. (Overrides Stream..::..Dispose(Boolean).)
Public methodEquals(Object)Determines whether the specified Object is equal to the current Object. (Inherited from Object.)
Protected methodFinalizeEnsures that resources are freed and other cleanup operations are performed when the garbage collector reclaims the FileStream. (Overrides Stream..::..Finalize()()()().)
Public methodFlushClears buffers for this stream and causes any buffered data to be written to the file. (Overrides Stream..::..Flush()()()().)
Public methodGetHashCodeServes as a hash function for a particular type. (Inherited from Object.)
Public methodGetTypeGets the Type of the current instance. (Inherited from Object.)
Protected methodMemberwiseCloneCreates a shallow copy of the current Object. (Inherited from Object.)
Public methodReadReads a block of bytes from the stream and writes the data in a given buffer. (Overrides Stream..::..Read(array<Byte>[]()[][], Int32, Int32).)
Public methodReadByteReads a byte from the stream and advances the position within the stream by one byte, or returns -1 if at the end of the stream. (Inherited from Stream.)
Public methodSeekSets the current position of this stream to the given value. (Overrides Stream..::..Seek(Int64, SeekOrigin).)
Public methodSetLengthSets the length of this stream to the given value. (Overrides Stream..::..SetLength(Int64).)
Public methodToStringReturns a string that represents the current object. (Inherited from Object.)
Public methodWriteWrites a block of bytes to the file stream. (Overrides Stream..::..Write(array<Byte>[]()[][], Int32, Int32).)
Public methodWriteByteWrites a byte to the current position in the stream and advances the position within the stream by one byte. (Inherited from Stream.)
Top

Use the FileStream class to read from, write to, open, and close files on a file system, and to manipulate other file-related operating system handles, including pipes, standard input, and standard output. FileStream buffers input and output for better performance.

The IsAsync property detects whether the file handle was opened asynchronously. You specify this value when you create an instance of the FileStream class using a constructor that has an isAsync, useAsync, or options parameter. When the property is true, the stream utilizes overlapped I/O to perform file operations asynchronously.

The Seek method supports random access to files. Seek allows the read/write position to be moved to any position within the file. This is done with byte offset reference point parameters. The byte offset is relative to the seek reference point, which can be the beginning, the current position, or the end of the underlying file, as represented by the three members of the SeekOrigin enumeration.

If a process terminates with part of a file locked or closes a file that has outstanding locks, the behavior is undefined.

For directory operations and other file operations, see the File, Directory, and Path classes. The File class is a utility class that has static methods primarily for the creation of FileStream objects based on file paths. The MemoryStream class creates a stream from a byte array and is similar to the FileStream class.

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
Show: