nsinputstream to string?
Is there anyway to view the 开发者_开发问答values in a nsinputstream such as converting it to a string?
I'll assume you mean the data that's returned from NSInputStream:
- (NSInteger)read:(uint8_t *)buffer maxLength:(NSUInteger)len;
Try this:
NSInteger bytesRead = [myInputStream read:&byteBuffer maxLength:4096];
NSString *stringFromData = [[NSString alloc] initWithBytes:byteBuffer length:bytesRead encoding:NSUTF8StringEncoding];
If you are reading the data from a stream that is pointing at a file or a URL, you could NSString methods:
+ stringWithContentsOfFile:encoding:error:
+ stringWithContentsOfURL:encoding:error:
See the NSString class reference for the documentation of these methods.
精彩评论