-dataWithContentsOfFile returning a NSData object, but no file exists?
-dataWithContentsOfFile returning a NSData object, but no file exists?
- Subject: -dataWithContentsOfFile returning a NSData object, but no file exists?
- From: email@hidden
- Date: Tue, 13 Dec 2005 23:18:54 -0800
I'm running some code that basically boils down to the following lines:
imageData = [NSData dataWithContentsOfFile:filepath];
if (imageData == nil) {
imageData = [NSData dataWithContentsOfFile:[[NSBundle mainBundle]
pathForImageResource:@"loading.png"]];
}
Unfortunately, in some cases (but not all), what I'm getting is an
NSData object that has zero bytes of Data. If I go to the directory
path specified in the "filepath" variable, there is no file - which I
figured should return a nil object instead of a valid object with
zero bytes of data.
But what's weird is that elsewhere in my program, I'm doing this:
if (![[NSFileManager defaultManager] fileExistsAtPath:photoFilePath]) {
NSData *photoData = [NSData dataWithContentsOfURL:url];
return [photoData writeToFile:cacheFilePath atomically:NO];
If the a file doesn't already exist, it should write it out. Both of
the above pieces of code run over and over again through a batch of
objects - loading from a URL and writing to a file if it doesn't
exist, and then elsewhere trying to read that data.
For some reason, NSFileManager is saying that fileExistsAtPath is
true, NSData is not returning nil, but is returning an NSData object
with zero bytes of data, but according to the Finder and spotlight,
the file does not exist.
This problem continues even if I quit and restart my program.
Any ideas where I should look? Is there some sort of caching that
goes on in NSFileManager and/or NSData that I can somehow reset?
thanks,
Blake
_______________________________________________
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