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

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

BinaryReader.BaseStream プロパティ

BinaryReader の基になるストリームへのアクセス公開します

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

Public Overridable ReadOnly
 Property BaseStream As Stream
Dim instance As BinaryReader
Dim value As Stream

value = instance.BaseStream
public virtual Stream BaseStream { get; }
/** @property */
public Stream get_BaseStream ()

プロパティ
BinaryReader関連付けられたストリーム

解説解説
使用例使用例

次に示すのは、MemoryStream クラス上で BinaryReader クラスと BinaryWriter クラス使用しメモリに対して Double データ読み取りと書き込み実行するコード例です。MemoryStreamByte データだけを読み書きます。

Imports System
Imports System.IO

Public Class BinaryRW

    Shared Sub Main()
    
        Dim i As Integer
        Const upperBound As Integer
 = 1000

        ' Create random data to write to the stream.
        Dim dataArray(upperBound) As Double
        Dim randomGenerator As New
 Random()
        For i = 0 To upperBound
            dataArray(i) = 100.1 * randomGenerator.NextDouble()
        Next i

        Dim binWriter As New
 BinaryWriter(New MemoryStream())
        Try

            ' Write data to the stream.
            Console.WriteLine("Writing data to the stream.")
            
            For i = 0 To upperBound
                binWriter.Write(dataArray(i))
            Next i

            ' Create a reader using the stream from the writer.
            Dim binReader As New
 BinaryReader(binWriter.BaseStream)

            ' Return to the beginning of the stream.
            binReader.BaseStream.Position = 0

            ' Read and verify the data.
            Try
                Console.WriteLine("Verifying the written data.")
                For i = 0 To upperBound
                    If binReader.ReadDouble() <> dataArray(i)
 Then
                        Console.WriteLine("Error writing data.")
                        Exit For
                    End If
                Next i
                Console.WriteLine("The data was written and verified.")
            Catch ex As EndOfStreamException
                Console.WriteLine("Error writing data: {0}.",
 _
                    ex.GetType().Name)
            End Try
        Finally
            binWriter.Close()
        End Try

    End Sub
End Class
using System;
using System.IO;

class BinaryRW
{
    static void Main()
    {
        int i;
        const int arrayLength = 1000;

        // Create random data to write to the stream.
        Random randomGenerator = new Random();
        double[] dataArray = new double[arrayLength];
        for(i = 0; i < arrayLength; i++)
        {
            dataArray[i] = 100.1 * randomGenerator.NextDouble();
        }

        using(BinaryWriter binWriter = 
            new BinaryWriter(new MemoryStream()))
        {
            // Write the data to the stream.
            Console.WriteLine("Writing data to the stream.");
            for(i = 0; i < arrayLength; i++)
            {
                binWriter.Write(dataArray[i]);
            }

            // Create a reader using the stream from the writer.
            using(BinaryReader binReader = 
                new BinaryReader(binWriter.BaseStream))
            {
                try
                {
                    // Return to the beginning of the stream.
                    binReader.BaseStream.Position = 0;

                    // Read and verify the data.
                    Console.WriteLine("Verifying the written data.");
                    for(i = 0; i < arrayLength; i++)
                    {
                        if(binReader.ReadDouble() != dataArray[i])
                        {
                            Console.WriteLine("Error writing data.");
                            break;
                        }
                    }
                    Console.WriteLine("The data was written " +
                        "and verified.");
                }
                catch(EndOfStreamException e)
                {
                    Console.WriteLine("Error writing data: {0}.",
                        e.GetType().Name);
                }
            }
        }
    }
}
using namespace System;
using namespace System::IO;
int main()
{
   int i;
   const int arrayLength = 1000;
   
   // Create random data to write to the stream.
   array<double>^dataArray = gcnew array<double>(arrayLength);
   Random^ randomGenerator = gcnew Random;
   for ( i = 0; i < arrayLength; i++ )
   {
      dataArray[ i ] = 100.1 * randomGenerator->NextDouble();

   }
   BinaryWriter^ binWriter = gcnew BinaryWriter( gcnew MemoryStream );
   try
   {
      
      // Write data to the stream.
      Console::WriteLine( "Writing data to the stream." );
      i = 0;
      for ( i = 0; i < arrayLength; i++ )
      {
         binWriter->Write( dataArray[ i ] );

      }
      
      // Create a reader using the stream from the writer.
      BinaryReader^ binReader = gcnew BinaryReader( binWriter->BaseStream );
      
      // Return to the beginning of the stream.
      binReader->BaseStream->Position = 0;
      try
      {
         
         // Read and verify the data.
         i = 0;
         Console::WriteLine( "Verifying the written data." );
         for ( i = 0; i < arrayLength; i++ )
         {
            if ( binReader->ReadDouble() != dataArray[ i ]
 )
            {
               Console::WriteLine( "Error writing data." );
               break;
            }

         }
         Console::WriteLine( "The data was written and verified." );
      }
      catch ( EndOfStreamException^ e ) 
      {
         Console::WriteLine( "Error writing data: {0}.", e->GetType()->Name
 );
      }

   }
   finally
   {
      binWriter->Close();
   }

}

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

class BinaryRW
{   
    public static void main(String[]
 args)
    {
        int i;
        final int arrayLength = 1000;

        // Create random data to write to the stream.
        Random randomGenerator = new Random();
        double dataArray[] = new double[arrayLength];
        for(i = 0;i < arrayLength;i++) {
            dataArray[i] = 100.1*randomGenerator.NextDouble() ;
        }
        BinaryWriter binWriter = new BinaryWriter(new
 MemoryStream());
        try {
            // Write the data to the stream.
            Console.WriteLine("Writing data to the stream.");
            for(i = 0;i < arrayLength;i++)    {
                binWriter.Write(dataArray [ i]);
            }
            // Create a reader using the stream from the writer.
            BinaryReader binReader = 
                new BinaryReader(binWriter.get_BaseStream());
            try {
                try {
                    // Return to the beginning of the stream.
                    binReader.get_BaseStream().set_Position(0);

                    // Read and verify the data.
                    Console.WriteLine("Verifying the written data.");
                    for(i = 0;i < arrayLength;i++) {
                        if ( binReader.ReadDouble() != dataArray[i]
 ) {
                            Console.WriteLine("Error writing data.");
                            break;
                        }
                    } 
                    Console.WriteLine(("The data was written "
                        + "and verified."));
                }
                catch(EndOfStreamException e) {
                    Console.WriteLine("Error writing data: {0}.",
                        e.GetType().get_Name());
                }
            }
            finally {
                if (binReader != null) {
                    binReader = null;
                }
            }
        }
        finally {
            if (binWriter != null) {
                binWriter = null;
            }
        }
    } //main
} //BinaryRW
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照


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

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

辞書ショートカット

すべての辞書の索引

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

   

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



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

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

©2024 GRAS Group, Inc.RSS