Stream.CanRead indicates whether the current stream supports reading. : Stream « File Stream « C# / C Sharp






Stream.CanRead indicates whether the current stream supports reading.

   

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.");
        }
    }
}

   
    
    
  








Related examples in the same category

1.Stream.CanWrite Property indicates whether the current stream supports writing.
2.Stream.CopyTo reads all the bytes from the current stream and writes them to the destination stream.
3.Stream.Read reads a sequence of bytes and advances the position
4.Create StreamWriter class for the specified stream, using the specified encoding and the default buffer size.
5.Create StreamWriter from FileStream
6.Create StreamWriter with encoding
7.Create StreamWriter from file name
8.UTF8 encoding StreamWriter
9.Create UTF8 encoding StreamWriter from File name
10.Set StreamWriter buffer size
11.Writes a subarray of characters to the stream.
12.Create a new instance of the StreamReader class for the specified stream.
13.Gets the current character encoding that the current StreamReader object is using.
14.Returns the next available character but does not consume it.
15.Reads a maximum of count characters from the current stream into buffer, beginning at index.
16.Reads the next character from the input stream and advances the character position by one character.
17.Read a single character
18.Reads a line of characters from the current stream and returns the data as a string.
19.Reads the stream from the current position to the end of the stream.
20.Copy Stream
21.Copy one Stream to another Stream
22.Authentication Stream
23.Outputs data from a read stream to a newly created file