我想在 Objective-C(命令行工具)中阅读一个简单的文本文件,这是我的代码
#import <Foundation/Foundation.h>
int main (int argc, const char * argv[])
{
@autoreleasepool {
// insert code here...
NSLog(@"Hello, World!");
NSBundle *bundle = [NSBundle mainBundle];
NSString *aPath = [bundle pathForResource:@"data" ofType:@"txt"];
BOOL fileExists = [[NSFileManager defaultManager] fileExistsAtPath:aPath];
if (fileExists) {
NSLog(@"THERE!");
} else {
NSLog(@"NOT THERE!");
}
但我尝试了完整路径,如/Users/Me/dat
a 或添加data.txt
到 xcode 中,但它不会加载文件,我错过了什么?谢谢你!