0
我正尝试读取我的iPhone应用程序资源文件夹中的目录。阅读iOS中的目录结构
NSString *path= [[NSBundle mainBundle] pathForResource:@"Capitalization" ofType:@"html" inDirectory:@"MyDirectory"];
NSLog(@"Path : %@",path);
BOOL fileExists = [[NSFileManager defaultManager] fileExistsAtPath:path];
if(fileExists){
NSString* content = [NSString stringWithContentsOfFile:path
encoding:NSUTF8StringEncoding
error:NULL];
NSLog(@"Data from plist %@",content);
}else {
NSLog(@"File Not Found");
//exit(1); // if file not found exit the application.
}
但每次我得到NULL。 请帮忙。我的目录也可以包含另一个目录,在这种情况下,我还必须获取目录名称。
你有没有看过NSFileManager的文档? –
你从哪里得到'NULL'?文件是否存在? 'NULL'是否记录了'content'?如果是这样,请使用'error'参数。这就是它的目的。告诉你为什么该方法失败。或者'路径''无'? – rmaddy
顺便说一句 - 在您的项目结构的资源部分,是MyDirectory文件夹是蓝色还是黄色? – rmaddy