Stream.CanRead 속성

정의

파생 클래스에서 재정의되면 현재 스트림이 읽기를 지원하는지를 나타내는 값을 가져옵니다.

public:
 abstract property bool CanRead { bool get(); };
public abstract bool CanRead { get; }
member this.CanRead : bool
Public MustOverride ReadOnly Property CanRead As Boolean

속성 값

Boolean

스트림이 읽기를 지원하면 true이고, 지원하지 않으면 false입니다.

예제

다음은 속성을 사용하는 예제입니다 CanRead .

using namespace System;
using namespace System::IO;
int main( void )
{
   FileStream^ fs = gcnew 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
   {
      Console::WriteLine( "MyFile.txt is not writable" );
   }

   return 0;
}
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.");
        }
    }
}
Imports System.IO

Class TestRW

    Public Shared Sub Main()
        Dim fs As New FileStream("MyFile.txt", FileMode.OpenOrCreate, FileAccess.Read)
        If fs.CanRead And fs.CanWrite Then
            Console.WriteLine("MyFile.txt can be both written to and read from.")
        Else
            If fs.CanRead Then
                Console.WriteLine("MyFile.txt is not writable.")
            End If
        End If
    End Sub
End Class

설명

파생된 Stream 클래스가 읽기를 지원하지 않는 경우 , ReadByteBeginRead 메서드를 Read호출하여 을 throw합니다NotSupportedException.

적용 대상

추가 정보