• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag
 

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Trouble reading a binary file.
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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
References: 
 >Trouble reading a binary file. (From: April Gendill <email@hidden>)

  • Prev by Date: waiting on a thread
  • Next by Date: Best way to email html?
  • Previous by thread: Re: Trouble reading a binary file.
  • Next by thread: Re: Trouble reading a binary file.
  • Index(es):
    • Date
    • Thread