我有2个一样的工程(Foundation Tool工程),2个工程的源码一样,都是这个:
#import <Foundation/Foundation.h>
int main (int argc, const char * argv[]) {
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
NSString * filename = @"~/CocoaProject/LearnObjectC/filestrings/filestrings.m";
filename = [filename stringByStandardizingPath];
printf("%s\n", [filename UTF8String]);
NSError * error;
NSString * source = [NSString stringWithContentsOfFile:filename
encoding:NSUTF8StringEncoding
error:&error];
if (error == nil)
{
NSLog(@"成功读取:%@", filename);
} else
{
NSLog(@"不成功:%@", [error description]);
}
printf("%s\n", [source UTF8String]);
[pool drain];
return 0;
}按说文件找到了应该跳到这里:NSLog(@"成功读取:%@", filename);
可是很奇怪的是,即便我能正常读取文件,依然会跳到NSLog(@"不成功:%@", [error description]);然后由于[error description]导致程序无法运行,我就是想知道造成这样结果的原因是什么... |