C# Program to Demonstrate the Use of Canread Property

You are currently viewing C# Program to Demonstrate the Use of Canread Property

C# program to demonstrate the use of CanRead property

using System;
using System.IO;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main()
        {
            byte[] b2 = new byte[6];

            FileStream f1;
            FileStream f2;

            f1 = new FileStream("abc.txt", FileMode.Open, FileAccess.Read);
            f2 = new FileStream("xyz.txt", FileMode.Open, FileAccess.Write);

            if (f1.CanRead)
                Console.WriteLine("Yes, It can read.");
            else
                Console.WriteLine("Yes, It can not read.");


            f1.Close();

            if (f2.CanRead)
                Console.WriteLine("Yes, It can read.");
            else
                Console.WriteLine("Yes, It can not read.");

            f2.Close();
        }
    }
}

Output

Yes, It can read.
Yes, It can not read.

Ranjith Kumar

Hi, I'm Ranjith a full-time Blogger, YouTuber, Affiliate Marketer, & founder of Coding Diksha. Here, I post about programming to help developers.

Leave a Reply