Re: Trouble reading a binary file.
Re: Trouble reading a binary file.
- Subject: Re: Trouble reading a binary file.
- From: Marcel Weiher <email@hidden>
- Date: Mon, 13 Dec 2004 16:19:01 +0000
On 13 Dec 2004, at 15:51, April Gendill wrote:
Below is the code I'm trying to use to read a binary file. I'm getting
an empty string though.. Can any one shed some light on this?
FILE * fptr;
fptr = fopen([[panel filename]cString],"rb");
char chr;
NSMutableString * fd =[[NSMutableString alloc]init];
while(chr =getc(fptr) != EOF){
[fd appendString:[NSString stringWithFormat:@"%c",chr]];
}
For binary files, don't use NSString. Use NSData instead. NSData
*myDate = [NSData dataWithContentsOfFile:[panel filename]];
NSString is for actual human readable (unicode) text and will interpret
your data, meaning that special character sequences will not get
represented 1:1 in your destination NSString. However, if you're using
NSString, you should also go for:
NSString *myString = [NSString stringWithContentsOfFile:[panel
filename]];
Marcel
-- Marcel Weiher Metaobject Software Technologies email@hidden
www.metaobject.com
The simplicity of power HOM, IDEAs, MetaAd etc.
1d480c25f397c4786386135f8e8938e4
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden