轉自 http://blog.csdn.net/zhaozy55555/article/details/7671491
貼出一個删除本地xml檔案的函數,檔案名為:”.weatherxml“
函數首先擷取程式的home路徑,再擷取檔案全路徑,之後調用NSFileManager:removeItemAtPath方法删除指定檔案
-(void)delWeatherXml
{
NSString * HomeDirectory;
NSString * theFilePath;
NSArray * arry=NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
if([arry count])
{
HomeDirectory= [[NSString alloc] initWithFormat:[arry objectAtIndex:0]];
NSLog(HomeDirectory);
}
theFilePath = [HomeDirectory stringByAppendingPathComponent:@".weatherxml"];
NSLog(theFilePath);
NSFileManager *defaultManager;
defaultManager = [NSFileManager defaultManager];
BOOL boolValue=[defaultManager removeItemAtPath: theFilePath error: nil];
if (boolValue)
{
NSLog(@"remove weatherxml file ok");
}
}