首先,您需要读取整个文件还是仅读取文件的一部分。如果您只需要读取文件的部分const int chunkSize = 1024; // read the file by chunks of 1KBusing (var file = File.OpenRead("yourfile")){ int bytesRead; var buffer = new byte[chunkSize]; while ((bytesRead = file.Read(buffer, 0 /* start offset */, buffer.Length)) > 0) { // TODO: Process bytesRead number of bytes from the buffer // not the entire buffer as the size of the buffer is 1KB // whereas the actual number of bytes that are read are // stored in the bytesRead integer. }}如果需要将整个文件加载到内存中。重复使用此方法而不是直接加载到内存中,因为您可以控制正在执行的操作,并且可以随时停止该过程。或者您可以使用https://msdn.microsoft.com/en-us/library/system.io.memorymappedfiles.memorymappedfile.aspx?f=255&MSPPError=-2147217396MemoryMappedFile内存映射文件将提供从内存访问的程序视图,但它只会第一次从磁盘加载。long offset = 0x10000000; // 256 megabyteslong length = 0x20000000; // 512 megabytes// Create the memory-mapped file.using (var mmf = MemoryMappedFile.CreateFromFile(@"c:\ExtremelyLargeImage.data", FileMode.Open,"ImgA")){ // Create a random access view, from the 256th megabyte (the offset) // to the 768th megabyte (the offset plus length). using (var accessor = mmf.CreateViewAccessor(offset, length)) { //Your process }}