Object-C-NSFileManager
+(NSFileManager *)defaultManager;//获得文件管理对象
-(BOOL)createFileAtPath:(NSString *)path contents:(NSData *)data attributes:(NSDictionary *)attr;//创建文件
-(BOOL)fileExistsAtPath:(NSString *)path;//判断一个文件是否存在
-(BOOL)fileExistsAtPath:(NSString *)path isDirectory:(BOOL *)isDirectory;
-(BOOL)copyItemAtPath:(NSString *)srcPath toPath:(NSString *)dstPath error:(NSError **)error;文件复制
-(BOOL)moveItemAtPath:(NSString *)srcPath toPath:(NSString *)dstPath error:(NSError**)error;文件移动
-(BOOL)removeItemAtPath:(NSString *)path error:(NSError **)error;/文件删除
// 如何进行浅度遍历
NSString *dirPath=@"/Users/administrator/Desktop/---";
NSFileManager *fm= [NSFileManager defaultManager];
NSArray *arr = [fm contentsOfDirectoryAtPath:dirPath error:nil];
NSLog(@"%@",arr);
//如何进行深度遍历
NSString *dirPath=@"/Users/administrator/Desktop/---";
NSFileManager *fm= [NSFileManager defaultManager];
NSDirectoryEnumerator *dirs=[fm enumeratorAtPath:dirPath];
NSString *path=[dirs nextObject];
while(path!=nil)
{
NSLog(@"%@",path);
path=[dirs nextObject];
}
//创建一个NSFileManager对象
NSFileManager *fm=[NSFileManager defaultManager];
NSString *path=@"/Users/administrator/Desktop/1.txt";
NSString *str=@"这是我创建的一个文件";
// 如何将字符串类型转化为NSdata;
NSData *data=[str dataUsingEncoding:NSUTF8StringEncoding];
BOOL flag=[fm createFileAtPath:path contents:data attributes:nil];
if(flag){
//success;
//读取文件内容,转化为字符串
NSString *fileContent=[NSString stringWithContentsOfFile:path encoding:NSUTF8StringEncoding error:nil];
NSLog(@"%@",fileContent);
}else{
//fail
}
转载于:https://www.cnblogs.com/Opaser/p/4563367.html
Object-C-NSFileManager相关推荐
- object-c中管理文件和目录:NSFileManager使用方法
object-c中管理文件和目录:NSFileManager使用方法 对于NSFileManager,文件或目录是使用文件的路径名唯一标识的.每一个路径名都是一个NSString对象,它可以是相对路径 ...
- 在kotlin companion object中读取Bean,注入Bean对象
在kotlin companion object中读取Bean,注入Bean对象 在使用kotlin时,或多或少地会使用到一些公共组件,如 http. mongo. redis相关的组件. 使用组 ...
- 在kotlin companion object中读取spring boot配置文件,静态类使用@Value注解配置
在kotlin companion object中读取配置文件 静态类使用@Value注解配置 class Config {@Value("\${name}")fun setNam ...
- Object的finalize()方法的作用是否与C++的析构函数作用相同
Object的finalize()方法的作用是否与C++的析构函数作用相同 public class Finalization {private static Finalization finaliz ...
- libgstreamer-1.0.so.0: cannot open shared object file: No such file or directory
1. 问题现象 error while loading shared libraries: libgstreamer-1.0.so.0: cannot open shared object file: ...
- RuntimeError: Expected object of backend CUDA but got backend CPU for argument
RuntimeError: Expected object of backend CUDA but got backend CPU for argument #4 'mat1' 原因:变量没有加cud ...
- RuntimeError: Expected object of device type cuda but got device type cpu for argument pytorch数据位置
RuntimeError: Expected object of device type cuda but got device type cpu for argument #2 'target' i ...
- Python错误:AttributeError: 'generator' object has no attribute 'next'解决办法
今天在学习生成器对象(generation object)运行以下代码时,遇到了一个错误: #定义生成器函数 def liebiao(): for x in range(10): yield x #函 ...
- Java OOP(Object Oriented Programming)个人理解及总结
面向对象编程(Object Oriented Programming,OOP,面向对象程序设计) 其三大特征:封装,继承,多态: 封装:解决数据的安全问题. 继承:解决代码的重用问题. 多态:解决程序 ...
- 目标检测数据集The Object Detection Dataset
目标检测数据集The Object Detection Dataset 在目标检测领域,没有像MNIST或Fashion MNIST这样的小数据集.为了快速测试模型,我们将组装一个小数据集.首先,我们 ...
最新文章
- 看日本电影再也不怕看不懂了,6行Python代码轻松实现音频转文字
- html制作第二页,订单第二页.html
- CentOS 终端显示中文异常解决办法
- 2007年淘宝网手机销量统计报告
- moment 时间戳_【通知】2020 CATTI 考试准考证打印时间
- 问道五周年服务器维护公告,问道五周年 欢乐嘉年华
- php2588,搞清楚一下必胜2588z和2582z哪个好点?都有些什么区别?内幕评测分析
- 一件事情没弄清楚,十有八九做不好
- Nginx 常见应用技术指南
- PLSQL调整SQL字体大小
- [转]100个经典C语言程序(益智类问题)
- matlab计算abc三相短路电流_不用到处问别人了,关于变压器的相关计算公式,都在这里!收藏好...
- Invalid prop:type check failed for prop“value“.Expected String with value“8“,got Number with value 8
- AD软件自动安装部署
- pamac 安装 ros-noetic-desktop-full(AUR) 失败后如何清理残留的问题
- 阿里云域名实名认证操作图文详情 新人必看
- The Accidental HFT Firm
- 中国天气雷达行业市场供需与战略研究报告
- 天邑ty1208z海思3798刷版本_陕西电信天邑ty1208z_s905m-b盒子刷安卓系统教程
- QT 显示动态GIF
热门文章
- Java JavaBean
- 编程语言对比 命名空间
- opencv-api convexityDefects
- 路西法第一季为什么会被打伤_《数码宝贝》第一季,为何只有亚古兽与加布兽会究极进化?...
- c语言删除数组重复元素并升序,C语言编程题: 编写函数,从一个已经排序的数组中删去某数后,该数组仍然有序....
- Linux详解系列2- 这100条常见命令你都用过哪些?
- Python到底能干什么
- App后台开发运维和架构实践学习总结(10)——基于Java-JWT前后端token认证实战使用详解
- Linux学习总结(22)——CentOS7.2安装Nginx
- Java基础学习总结(84)——Java面向对象六大原则和设计模式