我使用以下代码将文件从路径写入输出流,但每次我运行代码时,就我的文件大小(8MB 或 5MB 等)而言,它总是向流中写入 131768 个字节。有人可以帮我检查一下吗?我似乎找不到问题所在。还是有其他方法可以做到这一点?我正在使用带有以下代码的 NSStream:
NSString *filesContent = [[NSString alloc] initWithContentsOfFile:myMediaFile]; // myMediaFile is a path to my file eg. .../Documents/myvideo.mp4/
NSData *data = [ filesContent dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];
const uint8_t *buf = [data bytes];
NSUInteger length = [data length];
NSLog(@"datalen = %d",length);
NSInteger nwritten = [outputStream write:buf maxLength:length];
if (-1 == nwritten) {
NSLog(@"Error writing to stream %@: %@", outputStream, [outputStream streamError]);
}else{
NSLog(@"Wrote %ld bytes to stream %@.", (long long)nwritten, outputStream);
}