File.Exists返回true,OpenExisting失败,出现DirectoryNotFoundExceptio
本文关键字:失败 出现 DirectoryNotFoundExceptio OpenExisting File 返回 true Exists | 更新日期: 2023-09-27 18:20:17
我正在字符串中打开系统卷信息子文件夹中的内存映射文件。我知道并在资源管理器中看到它存在于那里,并且路径是正确的(它是从资源管理器复制粘贴的),而且该路径的File.exists返回true,但MemoryMappedFile.OpenExisting失败,出现DirectoryNotFoundException。为什么?(我拥有系统卷信息文件夹和子文件夹的所有权限)。
部分代码:
const string filePath = @"C:''System Volume Information''Foo''2.ext";
bool exists = File.Exists(filePath); //is true
using (MemoryMappedFile bitmapFile = MemoryMappedFile.OpenExisting(filePath, MemoryMappedFileRights.Read)) //Throws DirectoryNotFoundException
{
...
}
您需要使用MemoryMappedFile.CreateFromFile("yourPathToFileInDisk",FileMode.Open,"WhateverName")来打开您需要的文件。MemoryMappedFile.OpenExisting("WhateverName")尝试打开已存在的内存映射文件。
我还没有使用这些API,但我认为您需要首先将文件映射到内存。尝试MemoryMappedFile.CreateFromFile