Search Results for

    Show / Hide Table of Contents

    Class FileStream

    Provides a Stream for a file, supporting both synchronous and asynchronous read and write operations.

    Inheritance
    object
    MarshalByRefObject
    Stream
    FileStream
    Implements
    IDisposable
    Inherited Members
    Stream.CopyTo(Stream)
    Stream.Dispose()
    Stream.CanTimeout
    Stream.ReadTimeout
    Stream.WriteTimeout
    object.ToString()
    object.Equals(object)
    object.Equals(object, object)
    object.ReferenceEquals(object, object)
    object.GetHashCode()
    object.GetType()
    object.MemberwiseClone()
    Namespace: System.IO
    Assembly: System.IO.FileSystem.dll
    Syntax
    public class FileStream : Stream, IDisposable

    Constructors

    FileStream(string, FileMode, FileAccess)

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

    Declaration
    public FileStream(string path, FileMode mode, FileAccess access)
    Parameters
    Type Name Description
    string path

    A relative or absolute path for the file that the current FileStream object will encapsulate.

    FileMode mode

    One of the enumeration values that determines how to open or create the file.

    FileAccess access

    A bitwise combination of the enumeration values that determines how the file can be accessed by the FileStream object. This also determines the values returned by the CanRead and CanWrite properties of the FileStream object.

    FileStream(string, FileMode)

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

    Declaration
    public FileStream(string path, FileMode mode)
    Parameters
    Type Name Description
    string path

    A relative or absolute path for the file that the current FileStream object will encapsulate.

    FileMode mode

    One of the enumeration values that determines how to open or create the file.

    Properties

    CanRead

    Gets a value that indicates whether the current stream supports reading.

    Declaration
    public override bool CanRead { get; }
    Property Value
    Type Description
    bool
    Overrides
    Stream.CanRead

    CanSeek

    Gets a value that indicates whether the current stream supports seeking.

    Declaration
    public override bool CanSeek { get; }
    Property Value
    Type Description
    bool
    Overrides
    Stream.CanSeek

    CanWrite

    Gets a value that indicates whether the current stream supports writing.

    Declaration
    public override bool CanWrite { get; }
    Property Value
    Type Description
    bool
    Overrides
    Stream.CanWrite

    FilePath

    Gets the full file-system path of the current file, if the file has a path.

    Declaration
    public string FilePath { get; }
    Property Value
    Type Description
    string

    Length

    Gets the length in bytes of the stream.

    Declaration
    public override long Length { get; }
    Property Value
    Type Description
    long
    Overrides
    Stream.Length

    Name

    Gets the name of the file including the file name extension.

    Declaration
    public string Name { get; }
    Property Value
    Type Description
    string

    The name of the file including the file name extension.

    Position

    Gets or sets the current position of this stream.

    Declaration
    public override long Position { get; set; }
    Property Value
    Type Description
    long
    Overrides
    Stream.Position

    Methods

    Close()

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

    Declaration
    public override void Close()
    Overrides
    Stream.Close()

    Dispose(bool)

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

    Declaration
    protected override void Dispose(bool disposing)
    Parameters
    Type Name Description
    bool disposing

    true to release both managed and unmanaged resources; false to release only unmanaged resources.

    Overrides
    Stream.Dispose(bool)

    Finalize()

    Destructor

    Declaration
    protected override void Finalize()
    Overrides
    Stream.Finalize()

    Flush()

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

    Declaration
    public override void Flush()
    Overrides
    Stream.Flush()

    Read(byte[], int, int)

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

    Declaration
    public override int Read(byte[] buffer, int offset, int count)
    Parameters
    Type Name Description
    byte[] buffer

    When this method returns, contains the specified byte array with the values between offset and (offset + count - 1) replaced by the bytes read from the current source.

    int offset

    The byte offset in array at which the read bytes will be placed.

    int count

    The maximum number of bytes to read.

    Returns
    Type Description
    int

    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.

    Overrides
    Stream.Read(byte[], int, int)

    Read(SpanByte)

    Declaration
    public override int Read(SpanByte buffer)
    Parameters
    Type Name Description
    SpanByte buffer
    Returns
    Type Description
    int
    Overrides
    Stream.Read(SpanByte)

    ReadByte()

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

    Declaration
    public override int ReadByte()
    Returns
    Type Description
    int
    Overrides
    Stream.ReadByte()

    Seek(long, SeekOrigin)

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

    Declaration
    public override long Seek(long offset, SeekOrigin origin)
    Parameters
    Type Name Description
    long offset

    The point relative to origin from which to begin seeking.

    SeekOrigin origin

    Specifies the beginning, the end, or the current position as a reference point for offset, using a value of type SeekOrigin.

    Returns
    Type Description
    long

    The new position in the stream.

    Overrides
    Stream.Seek(long, SeekOrigin)

    SetLength(long)

    Sets the length of this stream to the given value.

    Declaration
    public override void SetLength(long value)
    Parameters
    Type Name Description
    long value

    The new length of the stream.

    Overrides
    Stream.SetLength(long)

    Write(byte[], int, int)

    Writes a block of bytes to the file stream.

    Declaration
    public override void Write(byte[] buffer, int offset, int count)
    Parameters
    Type Name Description
    byte[] buffer

    The buffer containing data to write to the stream.

    int offset

    The zero-based byte offset in array from which to begin copying bytes to the stream.

    int count

    The maximum number of bytes to write.

    Overrides
    Stream.Write(byte[], int, int)

    WriteByte(byte)

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

    Declaration
    public override void WriteByte(byte value)
    Parameters
    Type Name Description
    byte value

    A byte to write to the stream.

    Overrides
    Stream.WriteByte(byte)

    Implements

    IDisposable

    Extension Methods

    LogDispatcher.GetCurrentClassLogger(object)
    LogDispatcher.GetCurrentClassLogger(object)
    LogDispatcher.GetCurrentClassLogger(object)
    LogDispatcher.GetCurrentClassLogger(object)
    LogDispatcher.GetCurrentClassLogger(object)
    LogDispatcher.GetCurrentClassLogger(object)
    LogDispatcher.GetCurrentClassLogger(object)
    LogDispatcher.GetCurrentClassLogger(object)
    LogDispatcher.GetCurrentClassLogger(object)
    LogDispatcher.GetCurrentClassLogger(object)
    In This Article
    Back to top Copyright © 2023 nanoFramework Contributors
    Generated by DocFX