user768959
user768959

Reputation: 1

about the NSInputstream

-(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];

There in a file in Documents,I want to load into buffer use this method,but actuallyRead always -1, is there some wrong in my method?

Upvotes: 0

Views: 605

Answers (2)

kurgan
kurgan

Reputation: 83

The reason you always get -1, is that you forgot to open the stream, so all you have to do is insert the line [inStream open]; after you initialized your NSInputStream and before you try to read from it.

Upvotes: 2

crax
crax

Reputation: 391

You should check if the inStream is available by

if (nil == inStream)

Upvotes: 0

Related Questions