using System.IO; // Open a file in read-only mode FileInfo fileInfo = new FileInfo("example.txt"); FileStream fileStream = fileInfo.OpenRead(); // Read from the file byte[] buffer = new byte[fileInfo.Length]; fileStream.Read(buffer, 0, buffer.Length); // Close the file fileStream.Close();
using System.IO; // Open a file in read-only mode FileInfo fileInfo = new FileInfo("example.txt"); using (FileStream fileStream = fileInfo.OpenRead()) { // Read from the file byte[] buffer = new byte[fileInfo.Length]; fileStream.Read(buffer, 0, buffer.Length); }This code opens a file named "example.txt" in read-only mode, reads the content of the file into a byte array, and then automatically closes the file using the "using" statement. In conclusion, the "System.IO.FileInfo.OpenRead" method is a part of the "System.IO" namespace, which is a part of the standard .NET library. It allows opening a file in read-only mode and returns a "FileStream" object, which allows reading from the file.