NSData 转 bytes 字节数据
NSData *data = [NSData dataWithContentsOfFile:filePath];NSUInteger len = [data length];Byte *byteData = (Byte*)malloc(len);memcpy(byteData, [data bytes], len);
NSString *strPath = @"/Users/user/Desktop/jkk.txt"; NSLog(@"string = %@",[[NSString alloc]initWithContentsOfFile:strPath encoding:NSUTF8StringEncoding error:Nil]); NSData *strData = [[NSData alloc]initWithContentsOfFile:strPath]; NSLog(@"size = %d字节; strData = %@",strData.length,strData.description); NSUInteger len = [strData length]; Byte *byteData = (Byte*)malloc(len); memcpy(byteData, [strData bytes], len); for (int i = 0; i < len; i++) { printf("%c",byteData[i]); } NSData *Data222 = [[NSData alloc]initWithBytes:byteData length:len]; NSLog(@"Data222 : %@",Data222); NSRange rangeData = { 0,3}; NSData *subData = [strData subdataWithRange:rangeData]; NSLog(@"subData : %@",subData); NSData *Data333 = [[NSData alloc]initWithData:subData]; NSLog(@"Data333: %@",[[NSString alloc]initWithData:Data333 encoding:NSUTF8StringEncoding]);
result
参考: