在Objective C中,我有这样的东西:
uint8_t f[400000];
NSString *Str;
unsigned int count = 0;
NSError* error = nil;
Str = [[NSString alloc]initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"Test" ofType:@"txt"] encoding:NSUTF8StringEncoding error:&error];
@try {
NSInputStream *fin = [NSInputStream inputStreamWithData:[Str dataUsingEncoding:NSUTF8StringEncoding]];
count = [fin read:f maxLength:400000];
}
@catch (NSException * e) {
NSLog(@"Exception: %@", e);
}
@finally {
NSLog(@"finally");
}
我正在转换nsstring
然后nsinputstream
尝试阅读内容
但是在我调试代码之后,count
里面有-1,即读取时发生错误。我不明白我在这里做错了什么!有人可以帮帮我吗。
注意:Test.txt
是一个纯文本文件,内容只是“Hello”,调试节目Str
是用内容初始化的。这意味着try
块中有问题。
任何帮助表示赞赏。