Q:

C# program to demonstrate the use of CanWrite property

0

C# program to demonstrate the use of CanWrite property

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

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.CanWrite)
                Console.WriteLine("Yes, It can write.");
            else
                Console.WriteLine("Yes, It can not write.");


            f1.Close();

            if (f2.CanWrite)
                Console.WriteLine("Yes, It can write.");
            else
                Console.WriteLine("Yes, It can not write.");

            f2.Close();
        }
    }
}

Output

Yes, It can not write.
Yes, It can write.

In above program, we need to remember, when we use "FileStream" class then we need to include System.IO namespace in the program.

 

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now