BinaryReader.ReadChar メソッドとは? わかりやすく解説

Weblio 辞書 > コンピュータ > .NET Framework クラス ライブラリ リファレンス > BinaryReader.ReadChar メソッドの意味・解説 

BinaryReader.ReadChar メソッド

現在のストリーム次の文字読み取り使用した Encodingストリームから読み取った特定の文字に従ってストリーム現在位置進めます

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

例外例外
例外種類条件

EndOfStreamException

ストリーム末尾到達しました

ObjectDisposedException

ストリーム閉じられました。

IOException

I/O エラー発生しました

ArgumentException

サロゲート文字読み取られました。

解説解説

ReadChar メソッドストリーム内のサロゲート文字読み取ろうとした場合例外発生しストリーム内の位置進みますストリームシーク可能である場合ReadChar呼び出される前に位置は元の場所に戻されますが、ストリームシーク不可である場合位置修正されません。サロゲート文字ストリーム内にある可能性がある場合は、代わりに ReadChars メソッド使用します

データ形式競合するため、このメソッド次のエンコーディング使用することはお勧めしません。

その他の一般的な I/O タスクまたは関連する I/O タスクの例を次の表に示します

使用例使用例

メモリバッキング ストアとして使用してデータ読み書きする方法の例を次に示します

Imports System
Imports System.IO

Public Class BinaryRW

    Shared Sub Main()
    
        Dim i As Integer
 = 0
        Dim invalidPathChars() As Char
 = Path.InvalidPathChars
        Dim memStream As new
 MemoryStream()
        Dim binWriter As New
 BinaryWriter(memStream)

        ' Write to memory.
        binWriter.Write("Invalid file path characters are: ")
        For i = 0 To invalidPathChars.Length
 - 1
            binWriter.Write(invalidPathChars(i))
        Next i

        ' Create the reader using the same MemoryStream 
        ' as used with the writer.
        Dim binReader As New
 BinaryReader(memStream)

        ' Set Position to the beginning of the stream.
        memStream.Position = 0

        ' Read the data from memory and write it to the console.
        Console.Write(binReader.ReadString())
        Dim memoryData( _
            CInt(memStream.Length - memStream.Position) - 1) As
 Char
        For i = 0 To memoryData.Length - 1
            memoryData(i) = binReader.ReadChar()
        Next i
        Console.WriteLine(memoryData)
    
    End Sub
End Class
using System;
using System.IO;

class BinaryRW
{
    static void Main()
    {
        int i = 0;
        char[] invalidPathChars = Path.InvalidPathChars;
        MemoryStream memStream = new MemoryStream();
        BinaryWriter binWriter = new BinaryWriter(memStream);

        // Write to memory.
        binWriter.Write("Invalid file path characters are: ");
        for(i = 0; i < invalidPathChars.Length; i++)
        {
            binWriter.Write(invalidPathChars[i]);
        }

        // Create the reader using the same MemoryStream 
        // as used with the writer.
        BinaryReader binReader = new BinaryReader(memStream);

        // Set Position to the beginning of the stream.
        memStream.Position = 0;

        // Read the data from memory and write it to the console.
        Console.Write(binReader.ReadString());
        char[] memoryData = 
            new char[memStream.Length - memStream.Position];
        for(i = 0; i < memoryData.Length; i++)
        {
            memoryData[i] = binReader.ReadChar();
        }
        Console.WriteLine(memoryData);
    }
}
using namespace System;
using namespace System::IO;
int main()
{
   int i;
   array<Char>^invalidPathChars = Path::InvalidPathChars;
   MemoryStream^ memStream = gcnew MemoryStream;
   BinaryWriter^ binWriter = gcnew BinaryWriter( memStream );
   
   // Write to memory.
   binWriter->Write( "Invalid file path characters are: " );
   for ( i = 0; i < invalidPathChars->Length; i++ )
   {
      binWriter->Write( invalidPathChars[ i ] );

   }
   
   // Create the reader using the same MemoryStream 
   // as used with the writer.
   BinaryReader^ binReader = gcnew BinaryReader( memStream );
   
   // Set Position to the beginning of the stream.
   binReader->BaseStream->Position = 0;
   
   // Read the data from memory and write it to the console.
   Console::Write( binReader->ReadString() );
   array<Char>^memoryData = gcnew array<Char>(memStream->Length -
 memStream->Position);
   for ( i = 0; i < memoryData->Length; i++ )
   {
      memoryData[ i ] = binReader->ReadChar();

   }
   Console::WriteLine( memoryData );
}

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

class BinaryRW
{   
    public static void main(String[]
 args)
    {
        int i = 0;
        char invalidPathChars[] = Path.InvalidPathChars;
        MemoryStream memStream = new MemoryStream();
        BinaryWriter binWriter = new BinaryWriter(memStream);

        // Write to memory.
        binWriter.Write("Invalid file path characters are: ");
        for(i = 0;i < invalidPathChars.length;i++) {
            binWriter.Write(invalidPathChars[i]);
        }

        // Create the reader using the same MemoryStream 
        // as used with the writer.
        BinaryReader binReader = new BinaryReader(memStream);

        // Set Position to the beginning of the stream.
        memStream.set_Position(0);

        // Read the data from memory and write it to the console.
        Console.Write(binReader.ReadString());
        
        char memoryData[] = new char[(int)
            (memStream.get_Length() - memStream.get_Position())];
        for(i = 0;i < memoryData.length;i++) {
            memoryData[i] = binReader.ReadChar();
        } 
        Console.WriteLine(memoryData);
    } //main
} //BinaryRW
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照


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

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

辞書ショートカット

すべての辞書の索引

BinaryReader.ReadChar メソッドのお隣キーワード
検索ランキング

   

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



BinaryReader.ReadChar メソッドのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

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

©2024 GRAS Group, Inc.RSS