[英]nsinputstream to string?
无论如何都要查看nsinputstream中的值,例如将其转换为字符串?
I'll assume you mean the data that's returned from NSInputStream: 我假设你的意思是从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: 如果要从指向文件或URL的流中读取数据,则可以使用NSString方法:
+ stringWithContentsOfFile:encoding:error:
+ stringWithContentsOfURL:encoding:error:
See the NSString class reference for the documentation of these methods. 有关这些方法的文档,请参阅NSString类参考 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.