我想在我的应用程序文档文件夹中获取文件内容。所以我写了下面的代码。但是这段代码没有在我的应用程序文件夹中获取文件内容。在我的文档文件夹中包含我需要的文件。
- (void) displayContents
{
NSString *folderName = [@"Object File/" stringByAppendingString:strLastpath];
NSArray *dirPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *docsDir = [dirPaths objectAtIndex:0];
databasePath = [[NSString alloc] initWithString: [docsDir stringByAppendingPathComponent:folderName]];
NSError *theError = nil;
NSFileManager *filemgr;
NSArray *filelist;
int count;
int i;
filemgr =[NSFileManager defaultManager];
filelist = [filemgr contentsOfDirectoryAtPath:databasePath error:&theError];
count = [filelist count];
for (i = 0; i < count; i++)
{
NSLog(@"%@", filelist[i]);
}
}
我得到的错误是:
2013-10-14 11:18:55.680 SampleFileCreation[1599:c07] Database Path : /Users/mac/Library/Application Support/iPhone Simulator/6.1/Applications/3B43DFF3-6699-4D68-94A6-A5153F3B1404/Documents/Object File/banana.obj
2013-10-14 11:18:55.683 SampleFileCreation[1599:c07] File Exists
2013-10-14 11:18:55.685 SampleFileCreation[1599:c07] Error : The operation couldn’t be completed. (Cocoa error 260.)