BinaryReader.ReadChar メソッド
アセンブリ: mscorlib (mscorlib.dll 内)

Dim instance As BinaryReader Dim returnValue As Char returnValue = instance.ReadChar
現在のストリームから読み取った文字。


ReadChar メソッドがストリーム内のサロゲート文字を読み取ろうとした場合、例外が発生し、ストリーム内の位置が進みます。ストリームがシーク可能である場合、ReadChar が呼び出される前に位置は元の場所に戻されますが、ストリームがシーク不可である場合、位置は修正されません。サロゲート文字がストリーム内にある可能性がある場合は、代わりに ReadChars メソッドを使用します。
データ形式が競合するため、このメソッドを次のエンコーディングで使用することはお勧めしません。
その他の一般的な I/O タスクまたは関連する I/O タスクの例を次の表に示します。
File.AppendText FileInfo.AppendText | |
FileInfo.Length | |
File.GetAttributes | |
File.SetAttributes | |

メモリをバッキング ストアとして使用してデータを読み書きする方法の例を次に示します。
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

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


Weblioに収録されているすべての辞書からBinaryReader.ReadChar メソッドを検索する場合は、下記のリンクをクリックしてください。

- BinaryReader.ReadChar メソッドのページへのリンク