简体   繁体   中英

Delete Data from Nsdocument Directory

How can i delete data from NSDocumentDirectory which i have saved using the following code.

 NSArray *paths = NSSearchPathForDirectoriesInDomains (NSDocumentDirectory, NSUserDomainMask, YES);
 NSString *documentsDirectory = [paths objectAtIndex:0];
 NSString *fullFileName2 = [NSString stringWithFormat:@"%@nameArray", documentsDirectory];
 nameArray=[[NSMutableArray alloc]initWithContentsOfFile:fullFileName2];

 [nameArray addObject:nameField.text];
 [nameArray writeToFile:fullFileName2 atomically:NO];

try this :

NSArray *paths = NSSearchPathForDirectoriesInDomains (NSDocumentDirectory, NSUserDomainMask, YES);  

NSString *documentsDirectory = [paths objectAtIndex:0]; 

NSString *fullFileName2 = [NSString stringWithFormat:@"%@nameArray", documentsDirectory]; 

[[NSFileManager defaultManager] removeItemAtPath:fullFileName2 error: NULL];    

Try this,

 NSArray *paths = NSSearchPathForDirectoriesInDomains (NSDocumentDirectory, NSUserDomainMask, YES);
 NSString *documentsDirectory = [paths objectAtIndex:0];
 NSString *fullFileName2 = [nameArray objectAtIndex:0];
 [[NSFileManager defaultManager] removeItemAtPath:fullFileName2 error: NULL];

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM