iOS 关于文件操作 NSFileManager
- 创建文件夹
+ (BOOL)creatDir:(NSString *)path {
if (path.length==0) {
return NO;
}
NSFileManager *fileManager = [NSFileManager defaultManager];
BOOL isSuccess = YES;
BOOL isExist = [fileManager fileExistsAtPath:path];
if (isExist==NO) {
NSError *error;
if (![fileManager createDirectoryAtPath:path withIntermediateDirectories:YES attributes:nil error:&error]) {
isSuccess = NO;
NSLog(@"creat Directory Failed:%@",[error localizedDescription]);
}
}
return isSuccess;
} - 创建文件
+ (BOOL)creatFile:(NSString*)filePath {
if (filePath.length==0) {
return NO;
}
NSFileManager *fileManager = [NSFileManager defaultManager];
if ([fileManager fileExistsAtPath:filePath]) {
return YES;
}
NSError *error;
NSString *dirPath = [filePath stringByDeletingLastPathComponent];
BOOL isSuccess = [fileManager createDirectoryAtPath:dirPath withIntermediateDirectories:YES attributes:nil error:&error];
if (error) {
NSLog(@"creat File Failed:%@",[error localizedDescription]);
}
if (!isSuccess) {
return isSuccess;
}
isSuccess = [fileManager createFileAtPath:filePath contents:nil attributes:nil];
return isSuccess;
} - 写入文件
+ (BOOL)writeToFile:(NSString*)filePath contents:(NSData *)data {
if (filePath.length==0) {
return NO;
}
BOOL result = [self creatFile:filePath];
if (result) {
if ([data writeToFile:filePath atomically:YES]) {
NSLog(@"write Success");
}else{
NSLog(@"write Failed");
}
}
else{
NSLog(@"write Failed");
}
return result;
} - 追加数据
+ (BOOL)appendData:(NSData*)data withPath:(NSString *)filePath {
if (filePath.length==0) {
return NO;
}
BOOL result = [self creatFile:filePath];
if (result) {
NSFileHandle *handle = [NSFileHandle fileHandleForWritingAtPath:filePath];
[handle seekToEndOfFile];
[handle writeData:data];
[handle synchronizeFile];
[handle closeFile];
}
else{
NSLog(@"appendData Failed");
}
return result;
}
iOS 关于文件操作 NSFileManager的更多相关文章
- IOS 开发文件操作——NSFileManager
转自:http://blog.csdn.net/xyz_lmn/article/details/8968213,留着方便查阅 iOS的沙盒机制,应用只能访问自己应用目录下的文件.iOS不像androi ...
- iOS——文件操作NSFileManager (创建、删除,复制,粘贴)
iOS——文件操作NSFileManager (创建.删除,复制,粘贴) iOS的沙盒机制,应用只能访问自己应用目录下的文件.iOS不像android,没有SD卡概念,不能直接访问图像.视 ...
- iOS:文件操作相关(18-03-23更)
0.iOS文件系统 1.工程内文件 2.文件夹管理 3.文件操作 4.NSCache 附录: 1.沙盒文件夹.文件大小 2.清除沙盒 Library / Cache 下所有数据 3.测试plist 0 ...
- iOS文件和目录操作,iOS文件操作,NSFileManager使用文件操作:
NSFileManager常用的文件方法: -(NSData*)contentsAtPath:path 从一个文件中读取数据 -(BOLL)createFileAtPath:path contents ...
- Objective-C文件和目录操作,IOS文件操作,NSFileManager使用文件操作
http://blog.csdn.net/swingpyzf/article/details/15185767
- 文件操作 - NSFileManager
iOS的沙盒机制,应用只能访问自己应用目录下的文件.iOS不像android,没有SD卡概念,不能直接访问图像.视频等内容.iOS应用产生的内容,如图像.文件.缓存内容等都必须存储在自己的沙盒内.默认 ...
- iOS开发-文件操作
目录操作和文件管理 学习目标 1.理解单例 2.掌握NSFileManager类常用的文件管理操 3.掌握NSFileHandle类常用的文件数据操作 4.了解NSData类的常用操作 5.掌握Pli ...
- ios 关于文件操作 获取 文件大小
分类: Apple IPhone2012-06-28 11:31 4664人阅读 评论(0) 收藏 举报 ios语言manager测试c c语言 实现 #include "sys/stat ...
- iOS 的文件操作
直接上操作 效果:将一张图片写入文件 (图片本身已经在Assets.xcassets里面了) 1.获取当前app的沙盒路径 NSString *documentPath = NSSearchPathF ...
随机推荐
- mariadb,maria db
mariadb,maria db 继续紧逼Oracle:在占领谷歌等公司之后,MariaDB迈向企业端 发表于2013-10-25 13:00|10618次阅读|10条评论 MariaDB在Googl ...
- bzoj4504 k个串 kstring 可持久化线段树 (标记永久化)
[fjwc2015]k个串 kstring [题目描述] 兔子们在玩k个串的游戏.首先,它们拿出了一个长度为n的数字序列,选出其中的一个连续子串,然后统计其子串中所有数字之和(注意这里重复出现的数字只 ...
- 网页js粘贴截图
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title> ...
- cogs 66. [HAOI2004模拟] 数列问题
66. [HAOI2004模拟] 数列问题 ★☆ 输入文件:dfs3.in 输出文件:dfs3.out 简单对比时间限制:1 s 内存限制:128 MB 问题描述试编程将 1 至 N ...
- MongoDB使用教程收集(语法教程)
https://www.tutorialspoint.com/mongodb/index.htm https://wizardforcel.gitbooks.io/w3school-mongodb/c ...
- guava cache学习
Guava Cache与ConcurrentMap很相似,但也不完全一样.最基本的区别是ConcurrentMap会一直保存所有添加的元素,直到显式地移除.相对地,Guava Cache为了限制内存占 ...
- java压缩与解压文件
import java.io.BufferedInputStream; import java.io.BufferedOutputStream; import java.io.File; import ...
- no matching function transform?
http://stackoverflow.com/questions/19876746/stdtolower-and-visual-studio-2013 http://forums.codeguru ...
- CentOS 查看日志命令
cat tail -f 日 志 文 件 说 明 /var/log/message 系统启动后的信息和错误日志,是Red Hat Linux中最常用的日志之一 /var/log/secure 与安 ...
- hadoop的linux配置
一.新建hadoop组跟用户(password:hadoop) [root@localhost home]# groupadd hadoop [root@localhost home]# userad ...