我有代码
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
。
提前致谢!
答案 0 :(得分:3)
NSMutableDictionary *readDict = [[NSMutableDictionary alloc] initWithContentsOfFile:@"Stuff.plist"];
此行尝试从bundle目录中读取文件。从完整路径读取文件:
NSMutableDictionary *readDict = [[NSMutableDictionary alloc] initWithContentsOfFile:docsDirectoryWithPlist];