-(NSString*)dateFilePath{
NSArray *paths=NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory=[paths objectAtIndex:0];
return [documentsDirectory stringByAppendingPathComponent:kFileName];
}
- (void)viewDidLoad
{
int actuallyRead=0;
NSString *path=[self dateFilePath];
NSURL *audiourl=[[NSURL alloc]initFileURLWithPath:path];
NSLog(@"%@",audiourl);
inStream=[[NSInputStream alloc]initWithURL:audiourl];
actuallyRead=[inStream read:buffer maxLength:sizeof(buffer)];
NSLog(@"%d",actuallyRead);
[dataBuffer1 appendBytes:buffer length:actuallyRead];
NSLog(@"%d",actuallyRead);
[inStream release];
[super viewDidLoad];
}
IN .h file
NSInputStream *inStream;
NSMutableData *dateBuffer1;
unint8_t buffer[1024];在Documents中的一个文件中,我想使用此方法加载到缓冲区中,但actuallyRead总是-1,我的方法中有错误吗?
发布于 2012-08-22 20:27:41
您总是得到-1的原因是您忘记打开流,所以您所要做的就是在初始化NSInputStream之后尝试读取它之前插入行[inStream open];。
发布于 2011-06-22 18:41:42
您应该通过以下方式检查inStream是否可用
if (nil == inStream)https://stackoverflow.com/questions/6120120
复制相似问题