BCL mscorlib [00 00 00 00 00 00 00 00 04 00 00 00 00 00 00 00 ] 1.0.5000.0 2.0.0.0 4.0.0.0 All public static members of this type are safe for multithreaded operations. No instance members are guaranteed to be thread safe. System.IO.Stream System.Runtime.InteropServices.ComVisible(true)

The following example demonstrates the use of a object.

`using System; using System.IO; class Directory { public static void Main(String[] args) { FileStream fs = new FileStream("log.txt", FileMode.OpenOrCreate, FileAccess.Write); StreamWriter w = new StreamWriter(fs); w.BaseStream.Seek(0, SeekOrigin.End); // Set the file pointer to the end. Log ("Test1", w); Log ("Test2", w); w.Close(); // Close the writer and underlying file. fs = new FileStream("log.txt", FileMode.OpenOrCreate, FileAccess.Read); StreamReader r = new StreamReader(fs); r.BaseStream.Seek(0, SeekOrigin.Begin); DumpLog (r); } public static void Log (String logMessage, StreamWriter w) { w.Write("Log Entry : "); w.WriteLine("{0} {1}", DateTime.Now.ToLongTimeString(), DateTime.Now.ToLongDateString()); w.WriteLine(":"); w.WriteLine(":{0}", logMessage); w.WriteLine ("-------------------------------"); w.Flush(); } public static void DumpLog (StreamReader r) { while (r.Peek() > -1) { // While not at the end of the file, write to standard output. Console.WriteLine(r.ReadLine()); } r.Close(); } }`

Some example output is

Log Entry : 9:26:21 AM Friday, July 06, 2001

:

:Test1

-------------------------------

Log Entry : 9:26:21 AM Friday, July 06, 2001

:

:Test2

-------------------------------

Use the 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. You can use the , , , and methods to perform synchronous operations, or the , , , and methods to perform asynchronous operations. Use the asynchronous methods to perform resource-intensive file operations without blocking the main thread. This performance consideration is particularly important in a win8_appname_long app or desktop_appname app where a time-consuming stream operation can block the UI thread and make your app appear as if it is not working. buffers input and output for better performance.

The property detects whether the file handle was opened asynchronously. You specify this value when you create an instance of the class using a constructor that has an , , or parameter. When the property is true, the stream utilizes overlapped I/O to perform file operations asynchronously. However, the property does not have to be true to call the , , or method. When the property is false and you call the asynchronous read and write operations, the UI thread is still not blocked, but the actual I/O operation is performed synchronously.

The method supports random access to files. 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 enumeration.

Disk files always support random access. At the time of construction, the property value is set to true or false depending on the underlying file type.If the underlying file type is FILE_TYPE_DISK, as defined in winbase.h, the property value is true. Otherwise, the property value is false.

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 , , and classes. The class is a utility class that has static methods primarily for the creation of objects based on file paths. The class creates a stream from a byte array and is similar to the class.

For a list of common file and directory operations, see Common I/O Tasks.

## Detection of Stream Position Changes

When a object does not have an exclusive hold on its handle, another thread could access the file handle concurrently and change the position of the operating system's file pointer that is associated with the file handle. In this case, the cached position in the object and the cached data in the buffer could be compromised. The object routinely performs checks on methods that access the cached buffer to ensure that the operating system's handle position is the same as the cached position used by the object.

If an unexpected change in the handle position is detected in a call to the method, the .NET Framework discards the contents of the buffer and reads the stream from the file again. This can affect performance, depending on the size of the file and any other processes that could affect the position of the file stream.

If an unexpected change in the handle position is detected in a call to the method, the contents of the buffer are discarded and an exception is thrown.

A object will not have an exclusive hold on its handle when either the property is accessed to expose the handle or the object is given the property in its constructor.

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

- Constructor
  2.0.0.0
  4.0.0.0

  When is called, the handle is also closed and the file's handle count is decremented.

  FileStream assumes that it has exclusive control over the handle. Reading, writing, or seeking while a FileStream is also holding a handle could result in data corruption. For data safety, call before using the handle, and avoid calling any methods other than Close after you are done using the handle.

  When you compile a set of characters with a particular cultural setting and retrieve those same characters with a different cultural setting, the characters might not be interpretable, and could cause an exception to be thrown.

  FileShare.Read is the default for those constructors without a FileShare parameter.

  For a list of common file and directory operations, see Common I/O Tasks.

  Initializes a new instance of the class for the specified file handle, with the specified read/write permission.

  A file handle for the file that the current FileStream object will encapsulate.
  A constant that sets the and properties of the FileStream object.
- Constructor
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  System.Obsolete("Use FileStream(SafeFileHandle handle, FileAccess access) instead")

  When is called, the handle is also closed and the file's handle count is decremented.

  FileStream assumes that it has exclusive control over the handle. Reading, writing, or seeking while a FileStream is also holding a handle could result in data corruption. For data safety, call before using the handle, and avoid calling any methods other than Close after you are done using the handle.

  When you compile a set of characters with a particular cultural setting and retrieve those same characters with a different cultural setting, the characters might not be interpretable, and could cause an exception to be thrown.

  FileShare.Read is the default for those constructors without a FileShare parameter.

  For a list of common file and directory operations, see Common I/O Tasks.

  Initializes a new instance of the class for the specified file handle, with the specified read/write permission.

  A file handle for the file that the current FileStream object will encapsulate.
  A constant that sets the and properties of the FileStream object.
- Constructor
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  is a zero-length string, contains only white space, or contains one or more implementation-specific invalid characters.
  is .
  The caller does not have the required permission.

  is or , but the specified file cannot be found. If a different mode is specified and the file cannot be found, a new one is created.

  An I/O error occurred, such as specifying when the file specified by already exists.
  The directory information specified in does not exist.
  The length of or the absolute path information for exceeds the system-defined maximum length.

  contains an invalid value.

  Requires permission to read, write, and append to files. See , , and .

  The .NET Framework does not support direct access to physical disks through paths that are device names, such as "\\.\PHYSICALDRIVE0 ".

  The parameter can be a file name, including a file on a Universal Naming Convention (UNC) share.

  The constructor is given read/write access to the file, and it is opened sharing Read access (that is, requests to open the file for writing by this or another process will fail until the FileStream object has been closed, but read attempts will succeed). The buffer size is set to the default size of 4096 bytes (4 KB).

  is not required to be a file stored on disk; it can be any part of a system that supports access through streams. For example, depending on the system, this class can access a physical device.

  is true for all objects that encapsulate files. If indicates a device that does not support seeking, the property on the resulting is false. For additional information, see .

  FileShare.Read is the default for those constructors without a FileShare parameter.

  For constructors without a parameter, if the parameter is set to , is the default access. Otherwise, the access is set to .

  When you compile a set of characters with a particular cultural setting and retrieve those same characters with a different cultural setting, the characters might not be interpretable, and could cause an exception to be thrown.

  For a list of common file and directory operations, see Common I/O Tasks.

  Initializes a new instance of the class with the specified path and creation mode.

  A relative or absolute path for the file that the current FileStream object will encapsulate.
  A constant that determines how to open or create the file.
  0
- Constructor
  2.0.0.0
  4.0.0.0

  FileStream assumes that it has exclusive control over the handle. Reading, writing, or seeking while a FileStream is also holding a handle could result in data corruption. For data safety, call before using the handle, and avoid calling any methods other than Close after you are done using the handle. Alternately, read and write to the handle before calling this FileStream constructor.

  FileShare.Read is the default for those constructors without a FileShare parameter.

  When you compile a set of characters with a particular cultural setting and retrieve those same characters with a different cultural setting, the characters might not be interpretable, and could cause an exception to be thrown.

  For a list of common file and directory operations, see Common I/O Tasks.

  Initializes a new instance of the class for the specified file handle, with the specified read/write permission, and buffer size.

  A file handle for the file that the current FileStream object will encapsulate.
  A constant that gets the and properties of the FileStream object.
  A positive value greater than 0 indicating the buffer size. For values between one and eight, the actual buffer size is set to eight bytes.
- Constructor
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  System.Obsolete("Use FileStream(SafeFileHandle handle, FileAccess access) instead")

  The FileStream object is given the specified access to the file. The ownership of the handle will be as specified. If this process owns the handle, a call to the method will also close the handle and the file's handle count is decremented. The FileStream object is given the default buffer size of 8192 bytes.

  FileStream assumes that it has exclusive control over the handle. Reading, writing, or seeking while a FileStream is also holding a handle could result in data corruption. For data safety, call before using the handle, and avoid calling methods other than Close after you are done using the handle.

  FileShare.Read is the default for those constructors without a FileShare parameter.

  When you compile a set of characters with a particular cultural setting and retrieve those same characters with a different cultural setting, the characters might not be interpretable, and could cause an exception to be thrown.

  For a list of common file and directory operations, see Common I/O Tasks.

  Initializes a new instance of the class for the specified file handle, with the specified read/write permission and FileStream instance ownership.

  A file handle for the file that the current FileStream object will encapsulate.
  A constant that gets the and properties of the FileStream object.
  true if the file handle will be owned by this FileStream instance; otherwise, false.
- Constructor
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  is .

  is a zero-length string, contains only white space, or contains one or more implementation-specific invalid characters.

  -or-

  specified and specified , , or .

  is or , but the specified file was not found. If a different mode is specified and the file was not found, a new one is created.

  An I/O error occurred, such as specifying when the file specified by already exists.
  The caller does not have the required permission.
  The directory information specified by does not exist.
  specified a read-only file and is not , or specified a directory.
  The length of or the absolute path information for exceeds the system-defined maximum length.

  or contain an invalid value.

  Requires permission to read, write, and append to files. See , , and .

  The .NET Framework does not support direct access to physical disks through paths that are device names, such as "\\.\PHYSICALDRIVE0 ".

  The parameter can be a file name, including a file on a Universal Naming Convention (UNC) share.

  The constructor is given read/write access to the file, and it is opened sharing Read access (that is, requests to open the file for writing by this or another process will fail until the FileStream object has been closed, but read attempts will succeed). The buffer size is set to the default size of 8192 bytes (8 KB).

  is not required to be a file stored on disk; it can be any part of a system that supports access through streams. For example, depending on the system, this class can access a physical device.

  is true for all objects that encapsulate files. If indicates a device that does not support seeking, the property on the resulting is false. For additional information, see .

  FileShare.Read is the default for those constructors without a FileShare parameter.

  When you compile a set of characters with a particular cultural setting and retrieve those same characters with a different cultural setting, the characters might not be interpretable, and could cause an exception to be thrown.

  For a list of common file and directory operations, see Common I/O Tasks.

  Initializes a new instance of the class with the specified path, creation mode, and read/write permission.

  A relative or absolute path for the file that the current FileStream object will encapsulate.
  A constant that determines how to open or create the file.
  A constant that determines how the file can be accessed by the FileStream object. This gets the and properties of the FileStream object. is true if specifies a disk file.
  0
- Constructor
  2.0.0.0
  4.0.0.0

  You set the parameter to true to open the file handle asynchronously. When the parameter is true, the stream utilizes overlapped I/O to perform file operations asynchronously. However, the parameter does not have to be true to call the , , or method. When the parameter is false and you call the asynchronous read and write operations, the UI thread is still not blocked, but the actual I/O operation is performed synchronously.

  FileStream assumes that it has exclusive control over the handle. Reading, writing, or seeking while a FileStream is also holding a handle could result in data corruption. For data safety, call before using the handle, and avoid calling any methods other than Close after you are done using the handle. Alternately, read and write to the handle before calling this FileStream constructor.

  FileShare.Read is the default for those constructors without a FileShare parameter.

  When you compile a set of characters with a particular cultural setting and retrieve those same characters with a different cultural setting, the characters might not be interpretable, and could cause an exception to be thrown.

  For a list of common file and directory operations, see Common I/O Tasks.

  Initializes a new instance of the class for the specified file handle, with the specified read/write permission, buffer size, and synchronous or asynchronous state.

  A file handle for the file that this FileStream object will encapsulate.
  A constant that gets the and properties of the FileStream object.
  A positive value greater than 0 indicating the buffer size. For values between one and eight, the actual buffer size is set to eight bytes.
  true if the handle was opened asynchronously (that is, in overlapped I/O mode); otherwise, false.
- Constructor
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  System.Obsolete("Use FileStream(SafeFileHandle handle, FileAccess access, int bufferSize) instead")

  The FileStream object is given the specified access to the file. The ownership of the handle will be as specified. If this FileStream owns the handle, a call to the method will also close the handle. In particular, the file's handle count is decremented. The FileStream object is given the specified buffer size.

  FileStream assumes that it has exclusive control over the handle. Reading, writing, or seeking while a FileStream is also holding a handle could result in data corruption. For data safety, call before using the handle, and avoid calling any methods other than Close after you are done using the handle. Alternately, read and write to the handle before calling this FileStream constructor.

  FileShare.Read is the default for those constructors without a FileShare parameter.

  When you compile a set of characters with a particular cultural setting and retrieve those same characters with a different cultural setting, the characters might not be interpretable, and could cause an exception to be thrown.

  For a list of common file and directory operations, see Common I/O Tasks.

  Initializes a new instance of the class for the specified file handle, with the specified read/write permission, FileStream instance ownership, and buffer size.

  A file handle for the file that this FileStream object will encapsulate.
  A constant that gets the and properties of the FileStream object.
  true if the file handle will be owned by this FileStream instance; otherwise, false.
  A positive value greater than 0 indicating the buffer size. For values between one and eight, the actual buffer size is set to eight bytes.
- Constructor
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  is .
  is a zero-length string, contains only white space, or contains one or more implementation-specific invalid characters.

  is or , but the specified file cannot be found. If a different mode is specified and the file cannot be found, a new one is created.

  An I/O error occurred, such as specifying and the file specified by already exists.
  The caller does not have the required permission.
  The directory information specified by does not exist.
  The requested is not permitted by the operating system for the specified .
  The length of or the absolute path information for exceeds the system-defined maximum length.

  , , or contains an invalid value.

  Requires permission to read, write, and append to files. See , , and .

  The .NET Framework does not support direct access to physical disks through paths that are device names, such as "\\.\PHYSICALDRIVE0 ".

  The parameter can be a file name, including a file on a Universal Naming Convention (UNC) share.

  The constructor is given read/write access to the file, and it is opened sharing Read access (that is, requests to open the file for writing by this or another process will fail until the FileStream object has been closed, but read attempts will succeed). The buffer size is set to the default size of 8192 bytes (8 KB).

  is not required to be a file stored on disk; it can be any part of a system that supports access through streams. For example, depending on the system, this class can access a physical device.

  is true for all objects that encapsulate files. If indicates a device that does not support seeking, the property on the resulting is false. For additional information, see .

  When you compile a set of characters with a particular cultural setting and retrieve those same characters with a different cultural setting, the characters might not be interpretable, and could cause an exception to be thrown.

  For a list of common file and directory operations, see Common I/O Tasks.

  Initializes a new instance of the class with the specified path, creation mode, read/write permission, and sharing permission.

  A relative or absolute path for the file that the current FileStream object will encapsulate.
  A constant that determines how to open or create the file.
  A constant that determines how the file can be accessed by the FileStream object. This gets the and properties of the FileStream object. is true if specifies a disk file.
  A constant that determines how the file will be shared by processes.
  0
- Constructor
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  System.Obsolete("Use FileStream(SafeFileHandle handle, FileAccess access, int bufferSize, bool isAsync) instead")

  The FileStream object is given the specified access to the file. The ownership of the handle will be as specified. If this FileStream owns the handle, a call to the method will also close the handle. In particular, the file's handle count is decremented. The FileStream object is given the specified buffer size.

  FileStream assumes that it has exclusive control over the handle. Reading, writing, or seeking while a FileStream is also holding a handle could result in data corruption. For data safety, call before using the handle, and avoid calling any methods other than Close after you are done using the handle. Alternately, read and write to the handle before calling this FileStream constructor.

  FileShare.Read is the default for those constructors without a FileShare parameter.

  When you compile a set of characters with a particular cultural setting and retrieve those same characters with a different cultural setting, the characters might not be interpretable, and could cause an exception to be thrown.

  For a list of common file and directory operations, see Common I/O Tasks.

  Initializes a new instance of the class for the specified file handle, with the specified read/write permission, FileStream instance ownership, buffer size, and synchronous or asynchronous state.

  A file handle for the file that this FileStream object will encapsulate.
  A constant that gets the and properties of the FileStream object.
  true if the file handle will be owned by this FileStream instance; otherwise, false.
  A positive value greater than 0 indicating the buffer size. For values between one and eight, the actual buffer size is set to eight bytes.
  true if the handle was opened asynchronously (that is, in overlapped I/O mode); otherwise, false.
- Constructor
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  The parameter is .
  is a zero-length string, contains only white space, or contains one or more implementation-specific invalid characters.

  is less than or equal to zero.

  -or-

  , , or contain an invalid value.

  is or , but the specified file cannot be found. If a different mode is specified and the file cannot be found, a new one is created.

  An I/O error occurred, such as specifying and the file specified by already exists.
  The caller does not have the required permission.
  The directory information specified in does not exist.
  The requested is not permitted by the operating system for the specified .
  The length of or the absolute path information for exceeds the system-defined maximum length.
  Requires permission to read, write, and append to files. See , , and .

  The .NET Framework does not support direct access to physical disks through paths that are device names, such as "\\.\PHYSICALDRIVE0 ".

  The parameter can be a file name, including a file on a Universal Naming Convention (UNC) share.

  is not required to be a file stored on disk; it can be any part of a system that supports access through streams. For example, depending on the system, this class can access a physical device.

  is true for all objects that encapsulate files. If indicates a device that does not support seeking, the property on the resulting is false. For additional information, see .

  When you compile a set of characters with a particular cultural setting and retrieve those same characters with a different cultural setting, the characters might not be interpretable, and could cause an exception to be thrown.

  For a list of common file and directory operations, see Common I/O Tasks.

  Initializes a new instance of the class with the specified path, creation mode, read/write and sharing permission, and buffer size.

  A relative or absolute path for the file that the current FileStream object will encapsulate.
  A constant that determines how to open or create the file.
  A constant that determines how the file can be accessed by the FileStream object. This gets the and properties of the FileStream object. is true if specifies a disk file.
  A constant that determines how the file will be shared by processes.
  A positive value greater than 0 indicating the buffer size. For values between one and eight, the actual buffer size is set to eight bytes.
  0
- Constructor
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  is .
  is a zero-length string, contains only white space, or contains one or more implementation-specific invalid characters.

  is less than or equal to zero.

  -or-

  , , or contain an invalid value.

  is or , but the specified file cannot be found. If a different mode is specified and the file cannot be found, a new one is created.

  An I/O error occurred, such as specifying and the file specified by already exists.
  The caller does not have the required permission.
  The directory information specified by does not exist.
  The requested is not permitted by the operating system for the specified .
  The length of or the absolute path information for exceeds the system-defined maximum length.
  Requires permission to read, write, and append to files. See , , and .

  The .NET Framework does not support direct access to physical disks through paths that are device names, such as "\\.\PHYSICALDRIVE0 ".

  The parameter can be a file name, including a file on a Universal Naming Convention (UNC) share.

  is not required to be a file stored on disk; it can be any part of a system that supports access through streams. For example, depending on the system, this class can access a physical device.

  is true for all objects that encapsulate files. If indicates a device that does not support seeking, the property on the resulting is false. For additional information, see .

  When you compile a set of characters with a particular cultural setting and retrieve those same characters with a different cultural setting, the characters might not be interpretable, and could cause an exception to be thrown.

  For a list of common file and directory operations, see Common I/O Tasks.

  Initializes a new instance of the class with the specified path, creation mode, read/write and sharing permission, buffer size, and synchronous or asynchronous state.

  A relative or absolute path for the file that the current FileStream object will encapsulate.
  A constant that determines how to open or create the file.
  A constant that determines how the file can be accessed by the FileStream object. This gets the and properties of the FileStream object. is true if specifies a disk file.
  A constant that determines how the file will be shared by processes.
  A positive value greater than 0 indicating the buffer size. For values between one and eight, the actual buffer size is set to eight bytes.
  Specifies whether to use asynchronous I/O or synchronous I/O. However, note that the underlying operating system might not support asynchronous I/O, so when specifying true, the handle might be opened synchronously depending on the platform. When opened asynchronously, the and methods perform better on large reads or writes, but they might be much slower for small reads or writes. If the application is designed to take advantage of asynchronous I/O, set the parameter to true. Using asynchronous I/O correctly can speed up applications by as much as a factor of 10, but using it without redesigning the application for asynchronous I/O can decrease performance by as much as a factor of 10.
  0
- Constructor
  2.0.0.0
  4.0.0.0

  The .NET Framework does not support direct access to physical disks through paths that are device names, such as "\\.\PHYSICALDRIVE0 ".

  The parameter is used to provide access to more advanced operations that can be leveraged when creating a object.

  The parameter can be a file name, including a file on a Universal Naming Convention (UNC) share.

  is not required to be a file stored on disk; it can be any part of a system that supports access through streams. For example, depending on the system, this class can access a physical device.

  is true for all objects that encapsulate files. If indicates a device that does not support seeking, the property on the resulting is false. For additional information, see .

  When you compile a set of characters with a particular cultural setting and retrieve those same characters with a different cultural setting, the characters might not be interpretable, and could cause an exception to be thrown.

  For a list of common file and directory operations, see Common I/O Tasks.

  Initializes a new instance of the 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.

  A relative or absolute path for the file that the current FileStream object will encapsulate.
  A constant that determines how to open or create the file.
  A constant that determines how the file can be accessed by the FileStream object. This gets the and properties of the FileStream object. is true if specifies a disk file.
  A constant that determines how the file will be shared by processes.
  A positive value greater than 0 indicating the buffer size. For values between one and eight, the actual buffer size is set to eight bytes.
  A value that specifies additional file options.
- Constructor
  2.0.0.0
  4.0.0.0

  The .NET Framework does not support direct access to physical disks through paths that are device names, such as "\\.\PHYSICALDRIVE0 ".

  Use this constructor to apply access rights at the point of creation of a file. To access or modify rights on an existing file, consider using the and methods.

  The parameter is used to provide access to more advanced operations that can be leveraged when creating a object.

  The parameter can be a file name, including a file on a Universal Naming Convention (UNC) share.

  is not required to be a file stored on disk; it can be any part of a system that supports access through streams. For example, depending on the system, this class can access a physical device.

  is true for all objects that encapsulate files. If indicates a device that does not support seeking, the property on the resulting is false. For additional information, see .

  When you compile a set of characters with a particular cultural setting and retrieve those same characters with a different cultural setting, the characters might not be interpretable, and could cause an exception to be thrown.

  For a list of common file and directory operations, see Common I/O Tasks.

  Initializes a new instance of the class with the specified path, creation mode, access rights and sharing permission, the buffer size, and additional file options.

  A relative or absolute path for the file that the current object will encapsulate.
  A constant that determines how to open or create the file.
  A constant that determines the access rights to use when creating access and audit rules for the file.
  A constant that determines how the file will be shared by processes.
  A positive value greater than 0 indicating the buffer size. For values between one and eight, the actual buffer size is set to eight bytes.
  A constant that specifies additional file options.
- Constructor
  2.0.0.0
  4.0.0.0

  The .NET Framework does not support direct access to physical disks through paths that are device names, such as "\\.\PHYSICALDRIVE0 ".

  Use this constructor to apply access rights at the point of creation of a file. To access or modify rights on an existing file, consider using the and methods.

  The parameter is used to provide access to more advanced operations that can be leveraged when creating a object.

  The parameter can be a file name, including a file on a Universal Naming Convention (UNC) share.

  is not required to be a file stored on disk; it can be any part of a system that supports access through streams. For example, depending on the system, this class can access a physical device.

  is true for all objects that encapsulate files. If indicates a device that does not support seeking, the property on the resulting is false. For additional information, see .

  When you compile a set of characters with a particular cultural setting and retrieve those same characters with a different cultural setting, the characters might not be interpretable, and could cause an exception to be thrown.

  For a list of common file and directory operations, see Common I/O Tasks.

  Initializes a new instance of the class with the specified path, creation mode, access rights and sharing permission, the buffer size, additional file options, access control and audit security.

  A relative or absolute path for the file that the current object will encapsulate.
  A constant that determines how to open or create the file.
  A constant that determines the access rights to use when creating access and audit rules for the file.
  A constant that determines how the file will be shared by processes.
  A positive value greater than 0 indicating the buffer size. For values between one and eight, the actual buffer size is set to eight bytes.
  A constant that specifies additional file options.
  A constant that determines the access control and audit security for the file.
- Method
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  System.IAsyncResult `` `` `` `` `` The sum of is greater than the length of . is . or is negative. The asynchronous read operation attempted to read past the end of the file.

  In the .NET Framework 4 and earlier versions, you have to use methods such as and to implement asynchronous file operations. These methods are still available in the net_v45 to support legacy code; however, the new async methods, such as , , , and , help you implement asynchronous file operations more easily.

  must be called exactly once for every call to . Failing to end a read process before beginning another read can cause undesirable behavior such as deadlock.

  provides two different modes of operation: synchronous I/O and asynchronous I/O. While either can be used, the underlying operating system resources might allow access in only one of these modes. By default, opens the operating system handle synchronously. In Windows, this slows down asynchronous methods. If asynchronous methods are used, use the constructor.

  Use the property to determine whether the current instance supports reading. For additional information, see .

  If a stream is closed or you pass an invalid argument, exceptions are thrown immediately from . Errors that occur during an asynchronous read request, such as a disk failure during the IO request, occur on the thread pool thread and become visible upon a call to .

  must be called with this to find out how many bytes were read.

  Multiple simultaneous asynchronous requests render the request completion order uncertain.

  For a list of common file and directory operations, see Common I/O Tasks.

  Begins an asynchronous read operation. (Consider using instead; see the Remarks section.)

  An object that references the asynchronous read.

  The buffer to read data into. The byte offset in at which to begin reading. The maximum number of bytes to read. The method to be called when the asynchronous read operation is completed. A user-provided object that distinguishes this particular asynchronous read request from other requests. 0
- Method
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  System.IAsyncResult `` `` `` `` `` The sum of is greater than the length of . is . or is negative. An I/O error occurred. The stream does not support writing.

  In the .NET Framework 4 and earlier versions, you have to use methods such as and to implement asynchronous file operations. These methods are still available in the net_v45 to support legacy code; however, the new async methods, such as , , , and , help you implement asynchronous file operations more easily.

  must be called exactly once on every from . will block until the I/O operation has completed.

  This method overrides .

  provides two different modes of operation: synchronous I/O and asynchronous I/O. While either can be used, the underlying operating system resources might allow access in only one of these modes. By default, opens the operating system handle synchronously. In Windows, this slows down asynchronous methods. If asynchronous methods are used, use the constructor.

  If a stream is closed or you pass an invalid argument, exceptions are thrown immediately from . Errors that occur during an asynchronous write request, such as a disk failure during the IO request, occur on the thread pool thread and become visible upon a call to .

  Multiple simultaneous asynchronous requests render the request completion order uncertain.

  For a list of common file and directory operations, see Common I/O Tasks.

  Begins an asynchronous write operation. (Consider using instead; see the Remarks section.)

  An object that references the asynchronous write.

  The buffer containing data to write to the current stream. The zero-based byte offset in at which to begin copying bytes to the current stream. The maximum number of bytes to write. The method to be called when the asynchronous write operation is completed. A user-provided object that distinguishes this particular asynchronous write request from other requests. 0
- Property
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  System.Boolean

  if the stream supports reading; if the stream is closed or was opened with write-only access.

  If a class derived from does not support reading, calls to the , , and methods throw a .

  If the stream is closed, this property returns false.

  Gets a value indicating whether the current stream supports reading.

  0
- Property
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  System.Boolean

  if the stream supports seeking; if the stream is closed or if the was constructed from an operating-system handle such as a pipe or output to the console.

  If a class derived from does not support seeking, calls to , , , and throw a .

  If the stream is closed, this property returns false.

  Gets a value indicating whether the current stream supports seeking.

  0
- Property
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  System.Boolean

  if the stream supports writing; if the stream is closed or was opened with read-only access.

  If a class derived from does not support writing, a call to , , , or throws a .

  If the stream is closed, this property returns false.

  Gets a value indicating whether the current stream supports writing.

  0
- Method
  System.Void

  Closes the file and releases any resources associated with the current file stream.

  This method is equivalent to ().

  Any data previously written to the buffer is copied to the file before the file stream is closed, so it is not necessary to call before invoking . Following a call to , any operations on the file stream might raise exceptions. Invoking this method on the same instance multiple times does not result in an exception.

  The method invokes so that the file stream is closed before the garbage collector finalizes the object. However, objects writing to the , such as a , might not have flushed the data from their internal buffers to the when the call to closes the stream. To prevent data loss, always call on the highest-level object.

  This method overrides .

  0
  1.0.5000.0
- Method
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  System.Void `` An I/O error occurred.

  This method is called by the public method and the method. invokes the protected method with the parameter set to true. invokes with set to false.

  When the parameter is true, this method releases all resources held by any managed objects that this references. This method invokes the method of each referenced object.

  Releases the unmanaged resources used by the and optionally releases the managed resources.

  true to release both managed and unmanaged resources; false to release only unmanaged resources. 0
- Method
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  System.Int32 `` is . was not returned by a call to . was called multiple times with .

  In the .NET Framework 4 and earlier versions, you have to use methods such as and to implement asynchronous file operations. These methods are still available in the net_v45 to support legacy code; however, the new async methods, such as , , , and , help you implement asynchronous file operations more easily.

  must be called exactly for every call to . Failing to end a read process before beginning another read can cause undesirable behavior such as deadlock.

  This method overrides .

  can be called on every from . Calling tells you how many bytes were read from the stream. will block until the I/O operation has completed.

  Waits for the pending asynchronous read operation to complete. (Consider using instead; see the Remarks section.)

  The number of bytes read from the stream, between 0 and the number of bytes you requested. Streams only return 0 at the end of the stream, otherwise, they should block until at least 1 byte is available.

  The reference to the pending asynchronous request to wait for. 0
- Method
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  System.Void `` is . was not returned by a call to . was called multiple times with .

  In the .NET Framework 4 and earlier versions, you have to use methods such as and to implement asynchronous file operations. These methods are still available in the net_v45 to support legacy code; however, the new async methods, such as , , , and , help you implement asynchronous file operations more easily.

  This method overrides .

  must be called exactly once on every from . will block until the I/O operation has completed.

  Ends an asynchronous write operation and blocks until the I/O operation is complete. (Consider using instead; see the Remarks section.)

  The pending asynchronous I/O request. 0
- Method
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  System.Void

  The garbage collector calls Finalize when the current object is ready to be finalized. Finalize closes the FileStream.

  Ensures that resources are freed and other cleanup operations are performed when the garbage collector reclaims the FileStream.

  0
- Method
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  System.Void An I/O error occurred. The current instance has already been closed.

  This method overrides .

  When you call the method, the operating system I/O buffer is also flushed.

  A stream’s encoder is not flushed unless you explicitly call or dispose of the object. Setting to true means that data will be flushed from the buffer to the stream, but the encoder state will not be flushed. This allows the encoder to keep its state (partial characters) so that it can encode the next block of characters correctly. This scenario affects UTF8 and UTF7 where certain characters can only be encoded after the encoder receives the adjacent character or characters.

  Because a buffer can be used for either reading or writing, performs the following two functions:

  Any data previously written to the buffer is copied to the file and the buffer is cleared except for its encoder state.

  If is true and data was previously copied from the file to the buffer for reading, the current position within the file is decremented by the number of unread bytes in the buffer. The buffer is then cleared.

  Use the method overload when you want to ensure that all buffered data in intermediate file buffers is written to disk.

  Clears buffers for this stream and causes any buffered data to be written to the file.

  0
- Method
  4.0.0.0
  System.Void ``

  Use this overload when you want to ensure that all buffered data in intermediate file buffers is written to disk.

  When you call the method, the operating system I/O buffer is also flushed.

  Clears buffers for this stream and causes any buffered data to be written to the file, and also clears all intermediate file buffers.

  true to flush all intermediate file buffers; otherwise, false.
- Method
  4.0.0.0
  System.Threading.Tasks.Task ``

  When you call the method, the operating system I/O buffer is also flushed.

  If the operation is canceled before it completes, the returned task contains the value for the property. If the handle to the file is disposed, the returned task contains the exception in the property.

  Asynchronously clears all buffers for this stream, causes any buffered data to be written to the underlying device, and monitors cancellation requests.

  A task that represents the asynchronous flush operation.

  The token to monitor for cancellation requests.
- Method
  2.0.0.0
  4.0.0.0
  System.Security.AccessControl.FileSecurity

  While the class and can be used to retrieve the access control list (ACL) entries of an existing file, consider using method, as it is easier to use.

  Use the method to retrieve the ACL entries for a file.

  An ACL describes individuals and/or groups who have, or do not have, rights to specific actions on the given file. For more information, see ACL Technology Overview and How to: Add or Remove an Access Control List Entry.

  Gets a object that encapsulates the access control list (ACL) entries for the file described by the current object.

  An object that encapsulates the access control settings for the file described by the current object.

- Property
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  System.Obsolete("Use SafeFileHandle instead")
  System.IntPtr To be added.

  This property is an operating system handle for use with operating-system-provided system calls (such as ReadFile on Windows). It will not work with C library functions that expect a file descriptor, such as fread.

  The operating system handle might have been opened synchronously or asynchronously, depending on which FileStream constructor was called. Use the property to discover whether this handle was opened asynchronously. In Win32, this means the handle was opened for overlapped IO, and it requires different parameters to ReadFile and WriteFile.

  Data corruption might occur if a FileStream is created, its handle is passed, some operation moves the handle's file pointer, and then the FileStream is used again. Multiple threads cannot safely write to the same file simultaneously, and FileStream buffering code assumes that it exclusively controls the handle. FileStream might throw an if FileStream detects that some other process has moved the file pointer. To avoid this, do not write any data into a portion of the file that FileStream might have buffered, and restore the file pointer to the location it had when methods were last called on FileStream.

  Gets the operating system file handle for the file that the current FileStream object encapsulates.

- Property
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  System.Boolean

  if the current was opened asynchronously; otherwise, .

  The IsAsync property detects whether the FileStream handle was opened asynchronously, enabling your code to use the property correctly. In Win32, IsAsync being true means the handle was opened for overlapped I/O, and thus requires different parameters to ReadFile and WriteFile.

  You specify this value when you create an instance of the class using a constructor that has an , , or parameter. When the property is true, the stream utilizes overlapped I/O to perform file operations asynchronously. However, the property does not have to be true to call the , , or method. When the property is false and you call the asynchronous read and write operations, the UI thread is still not blocked, but the actual I/O operation is performed synchronously.

  Gets a value indicating whether the FileStream was opened asynchronously or synchronously.

  0
- Property
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  System.Int64

  A value containing the length of the stream in bytes.

  for this stream is . An I/O error occurred, such as the file being closed.

  For a list of common file and directory operations, see Common I/O Tasks.

  Gets the length in bytes of the stream.

  0
- Method
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  System.Void `` ``

  Locking a range of a file stream gives the threads of the locking process exclusive access to that range of the file stream.

  For a list of common file and directory operations, see Common I/O Tasks.

  Prevents other processes from reading from or writing to the .

  The beginning of the range to lock. The value of this parameter must be equal to or greater than zero (0). The range to be locked.
- Property
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  System.String To be added.

  For a list of common file and directory operations, see Common I/O Tasks.

  Gets the name of the FileStream that was passed to the constructor.

- Property
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  System.Int64

  A containing the current position of this stream.

  The current stream does not support seeking. An I/O error occurred. Attempted seeking past the end of a stream that does not support this. The value specified for a set operation is negative.

  Seeking to any location beyond the length of the stream is supported. When you seek beyond the length of the file, the file size grows. In Microsoft Windows NT and newer, any data added to the end of the file is set to zero. In Microsoft Windows 98 or earlier, any data added to the end of the file is not set to zero, which means that previously deleted data is visible to the stream. Setting the position of the stream to a large value beyond the end of the stream in Windows 98 or earlier may result in an exception being raised.

  For a list of common file and directory operations, see Common I/O Tasks.

  Gets or sets the current position of this stream.

  0
- Method
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  System.Int32 `` `` `` is . or is negative. The current stream does not support reading. An I/O error occurred. + is greater than the length of . The current stream is closed.

  This method overrides .

  The parameter gives the offset of the byte in (the buffer index) at which to begin reading, and the parameter gives the maximum number of bytes to be read from this stream. The returned value is the actual number of bytes read, or zero if the end of the stream is reached. If the read operation is successful, the current position of the stream is advanced by the number of bytes read. If an exception occurs, the current position of the stream is unchanged.

  The method returns zero only after reaching the end of the stream. Otherwise, always reads at least one byte from the stream before returning. If no data is available from the stream upon a call to , the method will block until at least one byte of data can be returned. An implementation is free to return fewer bytes than requested even if the end of the stream has not been reached.

  Use for reading primitive data types.

  Do not interrupt a thread that is performing a read operation. Although the application may appear to run successfully after the thread is unblocked, the interruption can decrease your application's performance and reliability.

  For a list of common file and directory operations, see Common I/O Tasks.

  Reads a block of bytes from the stream and writes the data in a given buffer.

  The total number of bytes read into the buffer. This might be less than the number of bytes requested if that number of bytes are not currently available, or zero if the end of the stream is reached.

  When this method returns, contains the specified byte array with the values between and ( + - 1 replaced by the bytes read from the current source. The byte offset in at which the read bytes will be placed. The maximum number of bytes to read. 0
- Method
  4.0.0.0
  System.Threading.Tasks.Task<System.Int32> `` `` `` ``

  The method enables you to perform resource-intensive file operations without blocking the main thread. This performance consideration is particularly important in a win8_appname_long app or desktop_appname app where a time-consuming stream operation can block the UI thread and make your app appear as if it is not working. The async methods are used in conjunction with the async and await keywords in Visual Basic and C#.

  Use the property to determine whether the current instance supports reading.

  If the operation is canceled before it completes, the returned task contains the value for the property. If the handle to the file is disposed, the returned task contains the exception in the property.

  Asynchronously reads a sequence of bytes from the current stream, advances the position within the stream by the number of bytes read, and monitors cancellation requests.

  A task that represents the asynchronous read operation. The value of the parameter contains the total number of bytes read into the buffer. The result value can be less than the number of bytes requested if the number of bytes currently available is less than the requested number, or it can be 0 (zero) if the end of the stream has been reached.

  The buffer to write the data into. The byte offset in at which to begin writing data from the stream. The maximum number of bytes to read. The token to monitor for cancellation requests.
- Method
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  System.Int32 The current stream is closed. The current stream does not support reading.

  This method overrides .

  Use the property to determine whether the current instance supports reading. For additional information, see .

  Reads a byte from the file and advances the read position one byte.

  The byte, cast to an , or -1 if the end of the stream has been reached.

  0
- Property
  2.0.0.0
  4.0.0.0
  Microsoft.Win32.SafeHandles.SafeFileHandle To be added.

  The property automatically flushes the stream and sets the current stream position to 0. This allows the file to be moved or the stream position to be reset by another stream using the returned by this property.

  Gets a object that represents the operating system file handle for the file that the current object encapsulates.

- Method
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  System.Int64 `` `` An I/O error occurred. The stream does not support seeking. Attempted seeking before the beginning of the stream or to more than one byte past the end of the stream. The current stream is closed.

  This method overrides .

  Use the property to determine whether the current instance supports seeking. For additional information, see .

  You can seek to any location beyond the length of the stream. When you seek beyond the length of the file, the file size grows. In Windows NT and later versions, data added to the end of the file is set to zero. In Windows 98 or earlier versions, data added to the end of the file is not set to zero, which means that previously deleted data is visible to the stream.

  For a list of common file and directory operations, see Common I/O Tasks.

  Sets the current position of this stream to the given value.

  The new position in the stream.

  The point relative to from which to begin seeking. Specifies the beginning, the end, or the current position as a reference point for , using a value of type . 0
- Method
  2.0.0.0
  4.0.0.0
  System.Void ``

  While the class and can be used on an existing file, consider using the method as it is easier to use.

  The method applies access control list (ACL) entries to a file that represents the noninherited ACL list.

  The ACL specified for the parameter replaces the existing ACL for the file. To add permissions for a new user, use the method to obtain the existing ACL, modify it, and then use to apply it back to the file.

  An ACL describes individuals and/or groups who have, or do not have, rights to specific actions on the given file. For more information, see ACL Technology Overview and How to: Add or Remove an Access Control List Entry.

  Applies access control list (ACL) entries described by a object to the file described by the current object.

  An object that describes an ACL entry to apply to the current file.
- Method
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  System.Void `` An I/O error occurred. The current stream does not support writing and seeking. is less than zero.

  This method overrides .

  If the given value is less than the current length of the stream, the stream is truncated. If the given value is larger than the current length of the stream, the stream is expanded. If the stream is expanded, the contents of the stream between the old and the new length are undefined.

  A stream must support both writing and seeking for SetLength to work.

  Use the property to determine whether the current instance supports writing, and the property to determine whether seeking is supported. For additional information, see and .

  For a list of common file and directory operations, see Common I/O Tasks.

  Sets the length of this stream to the given value.

  The new length of the stream. 0
- Method
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  System.Void `` ``

  For a list of common file and directory operations, see Common I/O Tasks.

  Allows access by other processes to all or part of a file that was previously locked.

  The beginning of the range to unlock. The range to be unlocked.
- Method
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  System.Void `` `` `` is . + is greater than the length of . or is negative. An I/O error occurred. The current stream does not support writing. An I/O error occurred.

  This method overrides .

  The parameter gives the offset of the byte in (the buffer index) at which to begin copying, and the parameter gives the number of bytes that will be written to the stream. If the write operation is successful, the current position of the stream is advanced by the number of bytes written. If an exception occurs, the current position of the stream is unchanged.

  Use the property to determine whether the current instance supports writing. For additional information, see .

  Do not interrupt a thread that is performing a write operation. Although the application may appear to run successfully after the thread is unblocked, the interruption can decrease your application's performance and reliability.

  For a list of common file and directory operations, see Common I/O Tasks.

  Writes a block of bytes to the file stream.

  The buffer containing data to write to the stream. The zero-based byte offset in from which to begin copying bytes to the stream. The maximum number of bytes to write. 0
- Method
  4.0.0.0
  System.Threading.Tasks.Task `` `` `` ``

  The method enables you to perform resource-intensive file operations without blocking the main thread. This performance consideration is particularly important in a win8_appname_long app or desktop_appname app where a time-consuming stream operation can block the UI thread and make your app appear as if it is not working. The async methods are used in conjunction with the async and await keywords in Visual Basic and C#.

  Use the property to determine whether the current instance supports reading.

  If the operation is canceled before it completes, the returned task contains the value for the property. If the handle to the file is disposed, the returned task contains the exception in the property.

  Asynchronously writes a sequence of bytes to the current stream, advances the current position within this stream by the number of bytes written, and monitors cancellation requests.

  A task that represents the asynchronous write operation.

  The buffer to write data from. The zero-based byte offset in from which to begin copying bytes to the stream. The maximum number of bytes to write. The token to monitor for cancellation requests.
- Method
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  System.Void `` The current stream is closed. The current stream does not support writing. The current stream is closed.

  This method overrides .

  Use WriteByte to write a byte to a FileStream efficiently. If the stream is closed or not writable, an exception will be thrown.

  Use the property to determine whether the current instance supports writing. For additional information, see .

  Writes a byte to the current position in the file stream.

  A byte to write to the stream. 0
0