0

我的项目的 Bundle 的 Documents 目录中有两个文本文件 (.txt)。当我在 xCode 中的 iPhone 模拟器上运行项目时,文件加载并正常工作,但是当我使用我的 iPhone 在 xCode 中运行相同的项目时,什么都没有加载。I have checked and the files don't even exist in the file directory when the iPhone is selected to run the project. 这是代码。同样,这工作正常,并且该文件存在于 xCode 中的 iPhone 模拟器下运行,但是当我使用我的 iPhone 作为设备运行它时,该文件不存在。

NSArray *arrayPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *docDir = [arrayPaths objectAtIndex:0];

NSString *path = [docDir stringByAppendingPathComponent:CURRENTPUZZLENUMBERFILE];

NSLog(@"Path = %@", path);  // for debugging
bool fileExists = [[NSFileManager defaultManager] fileExistsAtPath:path];
NSLog(@"File exists: %d", fileExists);   // for debugging
4

1 回答 1

1

以这种方式获取文件,然后您可以根据需要将其复制到您的文档目录

NSString *filePath = [[NSBundle mainBundle] pathForResource:CURRENTPUZZLENUMBERFILE ofType:@"txt"];
于 2013-06-12T20:57:03.230 回答