Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to close file after reading in Cocoa

I want to close all file after reading it. Actually, i want to remove safely the SD Card, so that i need to close all file before eject but i don't know how to close file. I used the code to reading file:

 NSError *error = nil;
    NSURL *url = [NSURL fileURLWithPath:[NSString stringWithFormat:@"%@/test.txt", drive_url]];
    NSLog(@"url %@",url);
    NSMutableData *dataText = [NSMutableData dataWithContentsOfURL:url options:NSDataReadingUncached error:&error];
    if (error) {
        NSLog(@"%@", [error localizedDescription]);
    }else {

        NSLog(@"Data loaded successfully");
        NSLog(@"Data %@",dataText);
    }

How can i close test.txt file? Thanks in advance

like image 543
Joson Daniel Avatar asked Dec 05 '25 10:12

Joson Daniel


1 Answers

File closes right after dataWithContentsOfURL:options:error: finished. NSDataReadingUncached is a hint indicating the file should not be stored in the file-system caches.

like image 154
Sviatoslav Yakymiv Avatar answered Dec 07 '25 00:12

Sviatoslav Yakymiv



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!