C# FileStream CanWrite
Description
FileStream CanWrite
Gets a value indicating whether
the current stream supports writing.
Syntax
FileStream.CanWrite
has the following syntax.
public override bool CanWrite { get; }
Example
//w ww .j av a2s . 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.