-1

如何删除NSDocumentDirectory使用以下代码保存的数据。

 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];
4

2 回答 2

2

试试这个 :

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

NSString *documentsDirectory = [paths objectAtIndex:0]; 

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

[[NSFileManager defaultManager] removeItemAtPath:fullFileName2 error: NULL];    
于 2013-01-22T06:47:33.030 回答
1

试试这个,

 NSArray *paths = NSSearchPathForDirectoriesInDomains (NSDocumentDirectory, NSUserDomainMask, YES);
 NSString *documentsDirectory = [paths objectAtIndex:0];
 NSString *fullFileName2 = [nameArray objectAtIndex:0];
 [[NSFileManager defaultManager] removeItemAtPath:fullFileName2 error: NULL];
于 2013-01-14T05:52:53.613 回答