// NSFileManager : 文件管理类
// 使用defaultManager 类方法,创建出单例对象
// 1. 创建对象
NSFileManager *fileManager= [NSFileManager defaultManager];
// 2.创建文件夹,将要创建的/path1/path2文件夹拼接到路径中
NSString*newPath1 = [documentPath stringByAppendingPathCom
[fileManager createDirectoryAtPath:newPath1//路径,包含要创建的新文件夹
// 3. 创建文件
NSString*filePath1= [newPath1 stringByAppendingPathCom
BOOLres = [fileManager createFileAtPath:filePath1contents:nilattributes:nil];
if(res) {
} else{
}
// 4. 写入文件
NSString*strData = @"这是准备写入的数据";
BOOLres2= [strData writeToFile:filePath1atomically:YESencoding:NSUTF8StringEncodingerror:nil];
if(res2) {
} else{
}
NSLog(@"%@",filePath1);
// 5.判断文件是否存在
if([fileManager fileExistsAtPath:filePath1]){
} else{
}
// 6. 删除文件
BOOLres3 = [fileManager removeItemAtPath:filePath1error:nil];
if(res3) {
} else{
}
联系客服