.NET Framework API Docs

System.IO.FileAccess Enum

The FileAccess enumeration specifies the type of access that a file can have, such as reading, writing, or both.

Namespace

System.IO

Assembly

System.Runtime.dll

Members

NameValueDescription
Read1Read access to the file.
Write2Write access to the file.
ReadWrite3Read and write access to the file.

Syntax

public enum FileAccess
{
    Read = 1,
    Write = 2,
    ReadWrite = 3
}

Usage Example (C#)

using System;
using System.IO;

class Example
{
    static void Main()
    {
        string path = @"C:\temp\sample.txt";

        // Open the file for reading and writing
        using (FileStream fs = new FileStream(path, FileMode.OpenOrCreate, FileAccess.ReadWrite))
        using (StreamWriter writer = new StreamWriter(fs))
        {
            writer.WriteLine("Hello, FileAccess!");
            writer.Flush();

            // Reset the position to the beginning for reading
            fs.Position = 0;
            using (StreamReader reader = new StreamReader(fs))
            {
                string content = reader.ReadToEnd();
                Console.WriteLine(content);
            }
        }
    }
}

Related Types