如果应用实现NSCachesDirectory下载文件,我想知道是不是也能通过编程的方法从 NSCachesDirectory中删除文件?
有很多方法,给你推荐一种:
NSArray *myPathList = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
NSString *mainPath = [myPathList objectAtIndex:0];
mainPath = [mainPath stringByAppendingPathComponent:DirectoryName];
在这里的mainPath是文件的全路径。
NSFileManager *fileManager = [NSFileManager defaultManager];
NSError *error;
BOOL fileExists = [fileManager fileExistsAtPath:mainPath];
if (fileExists)
{
BOOL success = [fileManager removeItemAtPath:mainPath error:&error];
if (!success) NSLog(@"Error: %@", [error localizedDescription]);
}