FileStream.CanRead プロパティとは? わかりやすく解説

Weblio 辞書 > コンピュータ > .NET Framework クラス ライブラリ リファレンス > FileStream.CanRead プロパティの意味・解説 

FileStream.CanRead プロパティ

現在のストリーム読み取りサポートしているかどうかを示す値を取得します

名前空間: System.IO
アセンブリ: mscorlib (mscorlib.dll 内)
構文構文

解説解説

Stream から派生したクラス読み取りサポートしてない場合に、Read、ReadByte、BeginRead の各メソッド呼び出すと、NotSupportedException がスローさます。

ストリーム閉じている場合、このプロパティfalse返します

使用例使用例

CanRead プロパティ使用する例を次に示します。このコード出力は "MyFile.txt is not writable." となりますFileStream コンストラクタFileAccess パラメータReadWrite変更すると、"MyFile.txt can be both written to and read from." というメッセージ出力されます。

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

import System.*;
import System.IO.*;

class TestRW
{
    public static void main(String[]
 args)
    {
        FileStream fs = new FileStream("MyFile.txt",
 
            FileMode.OpenOrCreate, FileAccess.Read);
        if (fs.get_CanRead() && fs.get_CanWrite()) {
            Console.WriteLine("MyFile.txt can be both written to " 
                + "and read from.");
        }
        else {
            if (fs.get_CanRead()) {
                Console.WriteLine("MyFile.txt is not writable.");
            }
        }
    } //main
} //TestRW
 import System;
 import System.IO;
 
class TestRW 
{
   public static function
 Main() : void 
   {
 
         var fs : FileStream = 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.");
      }
   }
}
TestRW.Main();
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照


このページでは「.NET Framework クラス ライブラリ リファレンス」からFileStream.CanRead プロパティを検索した結果を表示しています。
Weblioに収録されているすべての辞書からFileStream.CanRead プロパティを検索する場合は、下記のリンクをクリックしてください。
 全ての辞書からFileStream.CanRead プロパティ を検索

英和和英テキスト翻訳>> Weblio翻訳
英語⇒日本語日本語⇒英語
  

辞書ショートカット

すべての辞書の索引

FileStream.CanRead プロパティのお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



FileStream.CanRead プロパティのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2025 Microsoft.All rights reserved.

©2025 GRAS Group, Inc.RSS