views:

35

answers:

1

Hi, i has the following code which suppose to convert file to data but the problem is the byte size is not the size after the conversion can someone help me on this one? i'm suppose to send the NSdata using NSStream to a server.

NSString *file = [[NSString alloc] initWithContentsOfFile:filepath;  
NSLog(@"length = %d",[file length]); // file length is 248563 (Actual file size);

NSdata *data = [file dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:Yes];
NSLog(@"length = %d",[datalength]);// file length is 249199 (increase in file size);

Thanks in advance.

+2  A: 

Why load it into a string at all in the first place?

[NSData dataWithContentsOfFile:]

The problem with your code is that the file probably wasn't ASCII originally, so its reencoding things.

Joshua Weinberg