Not reading png file?


#1

Okay everything works until I added the last bit of code for “Reading an NSDate from a file.” I’ve looked over my code and I am stumped. I get 0 bytes read and I can’t see what I’ve done wrong, Here is my code

[code]#import <Foundation/Foundation.h>

int main(int argc, const char * argv[])
{

@autoreleasepool {
    
    NSURL *url = [NSURL URLWithString:@"http://www.google.com/images/logos/ps_logo2.png"];
    NSURLRequest *request = [NSURLRequest requestWithURL:url];
    NSError *error = nil;
    NSData *data = [NSURLConnection sendSynchronousRequest:request returningResponse:NULL error:&error];
    
    if (!data) {
        NSLog(@"fetch failed: %@", [error localizedDescription]);
        return 1;
    } 
   NSLog(@"The file is %lu bytes", [data length]);
                                    
   BOOL written = [data writeToFile:@"/tmp/google.png" options:NSDataWritingAtomic error:&error];
   
   if (!written) {
      NSLog(@"write failed: %@", [error localizedDescription]);
      return 1;
      }
   NSLog(@"success!");
    
    NSData *readData = [NSData dataWithContentsOfFile:@"/tmp/goggle.png"];
    NSLog(@"The file read from the disk has %lu bytes", [readData length]);
}
return 0;

}[/code]


#2

[quote=“donnyb”]Okay everything works until I added the last bit of code for “Reading an NSDate from a file.” I’ve looked over my code and I am stumped. I get 0 bytes read and I can’t see what I’ve done wrong, Here is my code

[code]

  [data writeToFile:@"/tmp/google.png" options:NSDataWritingAtomic error:&error];
   
   ''''''

    NSData *readData = [NSData dataWithContentsOfFile:@"/tmp/goggle.png"];

[/code][/quote]

You are writing to google and reading from goggle.