IOS文件处理
来源:互联网 发布:淘宝开店快递费用 编辑:程序博客网 时间:2024/06/10 18:15
简介
文件处理不能直观的通过应用程序来解释,我们可以从以下实例来了解IOS的文件处理。
IOS中对文件的操作. 因为应用是在沙箱(sandbox)中的,在文件读写权限上受到限制,只能在几个目录下读写文件。
文件处理中使用的方法
下面列出了用于访问和操作文件的方法的列表。
以下实例你必须替换FilePath1、FilePath和FilePath字符串为完整的文件路径,以获得所需的操作。
检查文件是否存在
NSFileManager *fileManager = [NSFileManager defaultManager]; //Get documents directory NSArray *directoryPaths = NSSearchPathForDirectoriesInDomains (NSDocumentDirectory, NSUserDomainMask, YES); NSString *documentsDirectoryPath = [directoryPaths objectAtIndex:0]; if ([fileManager fileExistsAtPath:@""]==YES) { NSLog(@"File exists"); }
比较两个文件的内容
if ([fileManager contentsEqualAtPath:@"FilePath1" andPath:@" FilePath2"]) { NSLog(@"Same content"); }
检查是否可写、可读、可执行文件
if ([fileManager isWritableFileAtPath:@"FilePath"]) { NSLog(@"isWritable"); } if ([fileManager isReadableFileAtPath:@"FilePath"]) { NSLog(@"isReadable"); } if ( [fileManager isExecutableFileAtPath:@"FilePath"]){ NSLog(@"is Executable"); }
移动文件
if([fileManager moveItemAtPath:@"FilePath1" toPath:@"FilePath2" error:NULL]){ NSLog(@"Moved successfully"); }
复制文件
if ([fileManager copyItemAtPath:@"FilePath1" toPath:@"FilePath2" error:NULL]) { NSLog(@"Copied successfully"); }
删除文件
if ([fileManager removeItemAtPath:@"FilePath" error:NULL]) { NSLog(@"Removed successfully"); }
读取文件
NSData *data = [fileManager contentsAtPath:@"Path"];
写入文件
[fileManager createFileAtPath:@"" contents:data attributes:nil];
0 0
- iOS文件处理介绍
- iOS之文件处理
- iOS文件处理
- iOS文件处理类
- IOS文件处理
- IOS 文件处理
- iOS 处理pfx文件
- IOS文件路径处理方法
- IOS文件路径处理方法
- IOS文件路径处理方法:
- IOS 文件路径字符串处理
- IOS文件路径处理方法:
- IOS文件路径处理方法
- IOS文件路径处理方法
- IOS文件路径处理方法:
- iOS开发 文件处理 路径设置
- iOS文件处理介绍(一)
- ios文件处理NSFileManager常见函数
- 单例GCD创建与图片生成缩略图
- MDK 查看局部变量显示<not in scope>
- 多线程socket通信server
- Java和c#开发语言的不同点
- 一个经典例子让你彻彻底底理解java回调机制
- IOS文件处理
- oracle 子查询因子化 浅谈(with的使用)
- HTML中的Hack手段之条件注释
- 2014过了,2015来了
- SOAP详解
- Ernest Adams总结50个最伟大的游戏创意
- 难道今天有点空闲,回来冒个泡。
- C# Post数据和接收简单示例【摘】
- 半数集问题