0

我有代码

 NSArray *paths = [[NSArray alloc]   
initWithArray:NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask, YES)]; 

NSString *docsDirectory = [[NSString alloc] initWithString:[paths objectAtIndex:0]];

NSLog(@"This app's documents directory: %@",docsDirectory);

NSString *docsDirectoryWithPlist = [[NSString alloc] initWithFormat:@"%@/Stuff.plist", docsDirectory];



BOOL fileExists = [[NSFileManager defaultManager] fileExistsAtPath:docsDirectoryWithPlist isDirectory:NO];

if (fileExists) 
{
    chdir([docsDirectory UTF8String]);
    NSMutableDictionary *readDict = [[NSMutableDictionary alloc] initWithContentsOfFile:@"Stuff.plist"];

在应用程序的applicationDidFinishLaunching方法中,每当它到达最后一行时,它就会崩溃,EXC_BAD_ACCESS一路抛出。

提前致谢!

4

1 回答 1

3
NSMutableDictionary *readDict = [[NSMutableDictionary alloc] initWithContentsOfFile:@"Stuff.plist"];

此行尝试从捆绑目录中读取文件。从完整路径读取文件:

NSMutableDictionary *readDict = [[NSMutableDictionary alloc] initWithContentsOfFile:docsDirectoryWithPlist];
于 2010-04-27T07:09:01.617 回答