C# FileStream CanRead

Description

FileStream CanRead Gets a value indicating whether the current stream supports reading.

Syntax

FileStream.CanRead has the following syntax.


public override bool CanRead { get; }

Example

The following example demonstrates a use of the CanRead property.


//from  w w  w  .j  a v a 2 s  . c  o  m
using System;
using System.IO;

class TestRW 
{
    public static void Main(String[] args)
    {
        FileStream fs = new FileStream("MyFile.txt", FileMode.OpenOrCreate, FileAccess.Read);
        if (fs.CanRead && fs.CanWrite)
        {
            Console.WriteLine("MyFile.txt can be both written to and read from.");
        }
        else if (fs.CanRead)
        {
            Console.WriteLine("MyFile.txt is not writable.");
        }
    }
}

The code above generates the following result.





















Home »
  C# Tutorial »
    System.IO »




BinaryReader
BinaryWriter
Directory
DirectoryInfo
DriveInfo
File
FileInfo
FileStream
MemoryStream
Path
StreamReader
StreamWriter
StringReader
StringWriter