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

Public Overrides Function Read ( _ <InAttribute> <OutAttribute> array As Byte(), _ offset As Integer, _ count As Integer _ ) As Integer
Dim instance As FileStream Dim array As Byte() Dim offset As Integer Dim count As Integer Dim returnValue As Integer returnValue = instance.Read(array, offset, count)
public: virtual int Read ( [InAttribute] [OutAttribute] array<unsigned char>^ array, int offset, int count ) override
public int Read ( /** @attribute InAttribute() */ /** @attribute OutAttribute() */ byte[] array, int offset, int count )
戻り値
バッファに読み取られた合計バイト数。要求しただけのバイト数を読み取れなかった場合、この値は要求したバイト数より小さくなります。ストリームの末尾に到達した場合は 0 になることがあります。


offset パラメータは読み取りを開始する位置の array のバイトのオフセット (バッファ インデックス) を指定し、count パラメータはこのストリームから読み取るバイトの最大数を指定します。戻り値は、実際に読み取ったバイト数であり、ストリームの末尾に到達している場合は 0 です。読み取り操作が正常に終了した場合、ストリームの現在位置は読み取ったバイト数だけ進みます。例外が発生した場合、ストリームの現在位置は変更されません。
Read メソッドは、ストリームの末尾に到達した後に必ず 0 を返します。それ以外の場合、Read は戻り値を返す前に常にストリームから少なくとも 1 バイトを読み取ります。Read の呼び出し時に利用できるデータがストリームにない場合、メソッドは少なくとも 1 バイトのデータを返すまでブロックします。メソッドの実装は、ストリームの末尾に到達していない場合でも、要求された数に満たないバイトを返すようにすることができます。
プリミティブ データ型を読み取る場合は BinaryReader を使用します。
その他の一般的な I/O タスクまたは関連する I/O タスクの例を次の表に示します。
File.AppendText FileInfo.AppendText | |
File.Move FileInfo.MoveTo | |
File.Copy FileInfo.CopyTo | |
FileInfo.Length | |
File.GetAttributes | |
File.SetAttributes | |
Directory.CreateDirectory Directory.CreateDirectory |

既存ファイルから指定したバイト数を読み取る例を次に示します。
Imports System Imports System.IO Class FSRead Public Shared Sub Main() 'Create a file stream from an existing file. Dim fi As New FileInfo("c:\csc.txt") Dim fs As FileStream = fi.OpenRead() 'Read 100 bytes into an array from the specified file. Dim nBytes As Integer = 100 Dim ByteArray(nBytes) As Byte Dim nBytesRead As Integer = fs.Read(ByteArray, 0, nBytes) Console.WriteLine("{0} bytes have been read from the specified file.", nBytesRead.ToString()) End Sub 'Main End Class 'FSRead
using System; using System.IO; class FSRead { public static void Main() { //Create a file stream from an existing file. FileInfo fi=new FileInfo("c:\\csc.txt"); FileStream fs=fi.OpenRead(); //Read 100 bytes into an array from the specified file. int nBytes=100; byte[] ByteArray=new byte[nBytes]; int nBytesRead=fs.Read(ByteArray, 0, nBytes); Console.WriteLine("{0} bytes have been read from the specified file." , nBytesRead.ToString()); } }
using namespace System; using namespace System::IO; int main() { //Create a file stream from an existing file. FileInfo^ fi = gcnew FileInfo( "c:\\csc.txt" ); FileStream^ fs = fi->OpenRead(); //Read 100 bytes into an array from the specified file. int nBytes = 100; array<Byte>^ByteArray = gcnew array<Byte>(nBytes); int nBytesRead = fs->Read( ByteArray, 0, nBytes ); Console::WriteLine( "{0} bytes have been read from the specified file.", nBytesRead ); }
import System.*; import System.IO.*; class FSRead { public static void main(String[] args) { //Create a file stream from an existing file. FileInfo fi = new FileInfo("c:\\csc.txt"); FileStream fs = fi.OpenRead(); //Read 100 bytes into an array from the specified file. int nBytes = 100; ubyte byteArray[] = new ubyte[nBytes]; int nBytesRead = fs.Read(byteArray, 0, nBytes); Console.WriteLine("{0} bytes have been read from the specified file." , ((Int32)nBytesRead).ToString()); } //main } //FSRead

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に収録されているすべての辞書からFileStream.Read メソッドを検索する場合は、下記のリンクをクリックしてください。

- FileStream.Read メソッドのページへのリンク