VB.NET
Dim fs As New System.IO.FileStream("C:\write.txt", _
System.IO.FileMode.Open, _
System.IO.FileAccess.Read)
Dim bs(fs.Length - 1) As Byte
fs.Read(bs, 0, bs.Length)
fs.Close()
C#System.IO.FileStream fs = new System.IO.FileStream(
@"C:\write.txt",
System.IO.FileMode.Open,
System.IO.FileAccess.Read);
byte[] bs = new byte[fs.Length];
fs.Read(bs, 0, bs.Length);
fs.Close();
ファイルを読み込む際にメモリ消費を抑制する方法VB.NET
Dim fs As New System.IO.FileStream("C:\write.txt", _
System.IO.FileMode.Open, _
System.IO.FileAccess.Read)
Dim bs As Byte() = New Byte(4095) {}
While True
Dim readSize As Integer = fs.Read(bs, 0, bs.Length)
If readSize = 0 Then
Exit While
End If
End While
fs.Close()
C#System.IO.FileStream fs = new System.IO.FileStream(
@"C:\write.txt",
System.IO.FileMode.Open,
System.IO.FileAccess.Read);
byte[] bs = new byte[0x1000];
for (; ; )
{
int readSize = fs.Read(bs, 0, bs.Length);
if (readSize == 0)
break;
}
fs.Close();