代码复制如下。我正在使用文档目录,因为我知道您可以在应用程序沙箱之外进行编写。我还比较了我用来确定由 NSFileManager 创建的路径的字符串,它们是相同的。大家怎么看?
- (NSString *)documentsDirectory
{
NSArray *paths=NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask, YES);
return [paths objectAtIndex:0];
}
- (void) whateverFunction{
NSString *memfileName = @"memmapfile.map";
NSString *filePath = [[self documentsDirectory] stringByAppendingPathComponent:memfileName];
NSLog(@"Here is the filePath: %@", filePath);
NSLog(@"Other version: %s", [[NSFileManager defaultManager] fileSystemRepresentationWithPath:filePath]);
int memFD = open([filePath cStringUsingEncoding:NSASCIIStringEncoding], O_RDWR);
NSLog(@"I am getting -1 for memFD: %d", memFD);
}