【发布时间】:2012-04-09 03:20:39
【问题描述】:
我正在尝试逐行读取文本文件,文本文件将是一个非常小的文件,所以我只使用了:
NSString *fileContents = [NSString stringWithContentsOfFile:filePath encoding:NSUTF8StringEncoding error:nil];
但是,该行引发了一个异常,说:
[NSURL getFileSystemRepresentation:maxLength:]: unrecognized selector sent to instance 0x7f92c40e1890
我真的是 Objective-C 的新手,我不明白为什么会这样......
提前致谢。
NSString *filePath;
NSOpenPanel *fileBrowser = [NSOpenPanel openPanel];
[fileBrowser setCanChooseFiles:YES];
[fileBrowser setCanChooseDirectories:YES];
if ([fileBrowser runModal] == NSOKButton) {
NSArray *files = [fileBrowser URLs];
for ( int i = 0; i < [files count]; i++ ) {
filePath = [files objectAtIndex:i];
}
}
这是因为 [fileBrowser URLs] 部分吗? 谢谢。
【问题讨论】:
-
我猜你在不应该的时候创建了 filePath 作为 NSURL。请发布创建它的代码。
标签: objective-c xcode cocoa exception osx-lion