objective-c之文件处理
来源:互联网 发布:朱峰 知乎 编辑:程序博客网 时间:2024/06/06 04:31
//// main.m// 文件处理//// Created by wu jianhua on 16-8-3.// Copyright (c) 2016年 wujianhua. All rights reserved.//#import <Foundation/Foundation.h>//http://www.yiibai.com/objective_c/objective_c_file_handling.htmlint main(int argc, const char * argv[]){ char* path[1024]={0}; printf("currentDir=%s",getcwd(path, 1024)); @autoreleasepool { NSFileManager *fileManager = [NSFileManager defaultManager]; //Get documents directory NSArray *directoryPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); NSString *documentsDirectoryPath = [directoryPaths objectAtIndex:0]; NSLog(@"documentsDirectoryPath=%@",documentsDirectoryPath); documentsDirectoryPath=@"/Users/wujianhua/Desktop/test/hehe.txt"; if ([fileManager fileExistsAtPath:documentsDirectoryPath]==YES) { NSLog(@"File exists"); } if ([fileManager isWritableFileAtPath:documentsDirectoryPath]) { NSLog(@"isWritable"); } if ([fileManager isReadableFileAtPath:documentsDirectoryPath]) { NSLog(@"isReadable"); } if ( [fileManager isExecutableFileAtPath:documentsDirectoryPath]){ NSLog(@"is Executable"); } if ([fileManager contentsEqualAtPath:@"/Users/wujianhua/Desktop/test/hehe.txt" andPath:@" /Users/wujianhua/Desktop/test/hehe.txt"]) { NSLog(@"Same content"); }else{ NSLog(@"no Same content"); } //复制文件 if ([fileManager copyItemAtPath:@"/Users/wujianhua/Desktop/test/hehe.txt" toPath:@"/Users/wujianhua/Desktop/test/hehe2.txt" error:NULL]) { NSLog(@"Copied successfully"); } //移动文件 if([fileManager moveItemAtPath:@"/Users/wujianhua/Desktop/test/hehe2.txt" toPath:@"/Users/wujianhua/Desktop/hehe2.txt" error:NULL]){ NSLog(@"Moved successfully"); } //删除文件 // if ([fileManager removeItemAtPath:@"/Users/wujianhua/Desktop/hehe2.txt" error:NULL]) { NSLog(@"Removed successfully"); // } //读取文件 NSData *data = [fileManager contentsAtPath:@"/Users/wujianhua/Desktop/hehe.txt"]; //写文件 [fileManager createFileAtPath:@"/Users/wujianhua/Desktop/hehe_out.txt" contents:data attributes:nil]; } return 0;}
0 0
- objective-c之文件处理
- Objective-C 文件处理
- objective-c之错误处理
- objective-c之查找文件
- Objective C 之文件管理
- Objective-C中对文件的处理
- Objective-C语法之异常处理
- Objective-C语法之异常处理
- Objective-C语法之异常处理
- 5,Objective-C语法之异常处理
- Objective-C语法之异常处理
- Objective-C语法之异常处理
- 6、Objective-C语法之异常处理
- Objective-C语法之异常处理
- Objective-C语法之异常处理
- Objective-C语法之异常处理
- Objective-C语法之异常处理
- Objective-C学习笔记-之操作文件
- linux awk命令详解
- [转]调用startActivityForResult后,onActivityResult为什么立刻响应
- NOIP2012复赛day1 Vigenère密码 简单的一题
- Web压力测试工具:http_load、webbench、ab、Siege使用教程
- Android OpenGL ES 开发教程(一)
- objective-c之文件处理
- NYOJ 82 迷宫寻宝(一)(多次 bfs)
- php发送邮件email
- 数字签名和数字证书是什么?
- 项目风险管理
- activemq学习笔记——入门
- git 忽略文件
- VS常用快捷键
- android 常见分辨率(mdpi、hdpi 、xhdpi、xxhdpi )及屏幕适配注意事项