Stream.CanWrite Özellik

Tanım

Türetilmiş bir sınıfta geçersiz kılındığında, geçerli akışın yazmayı destekleyip desteklemediğini belirten bir değer alır.

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

Özellik Değeri

true akış yazmayı destekliyorsa; aksi takdirde , false.

Örnekler

Aşağıda özelliğinin kullanımına bir örnek verilmiştir CanWrite .

using namespace System;
using namespace System::IO;
int main()
{
   FileStream^ fs = gcnew FileStream( "MyFile.txt",FileMode::OpenOrCreate,FileAccess::Write );
   if ( fs->CanRead && fs->CanWrite )
   {
      Console::WriteLine( "MyFile.txt can be both written to and read from." );
   }
   else
   if ( fs->CanWrite )
   {
      Console::WriteLine( "MyFile.txt is writable." );
   }
}

//This code outputs "MyFile.txt is writable."
//To get the output message "MyFile.txt can be both written to and read from.",
//change the FileAccess parameter to ReadWrite in the FileStream constructor.
using System;
using System.IO;

class TestRW
{
  public static void Main(String[] args)
  {
    FileStream fs = new FileStream("MyFile.txt", FileMode.OpenOrCreate,
       FileAccess.Write);
    if (fs.CanRead && fs.CanWrite) {
        Console.WriteLine("MyFile.txt can be both written to and read from.");
    }
    else if (fs.CanWrite) {
        Console.WriteLine("MyFile.txt is writable.");
    }
  }
}
//This code outputs "MyFile.txt is writable."
//To get the output message "MyFile.txt can be both written to and read from.",
//change the FileAccess parameter to ReadWrite in the FileStream constructor.
Imports System.IO

Class TestRW    

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

'This code outputs "MyFile.txt is writable."
'To get the output message "MyFile.txt can be both written to and read from.",
'change the FileAccess parameter to ReadWrite in the FileStream constructor.

Açıklamalar

öğesinden Stream türetilen bir sınıf yazmayı desteklemiyorsa , veya WriteByte çağrısı WriteBeginWriteoluştururNotSupportedException. Böyle durumlarda, Flush salt okunur bir akışı temizlemek geçerli olduğundan, diğer Stream türlerle tam uyumluluğu sağlamak için genellikle boş bir yöntem olarak uygulanır.

Şunlara uygulanır

Ayrıca bkz.