2019独角兽企业重金招聘Python工程师标准>>>
每个程序在沙盒下都有几个文件:
documents,tmp,app,Library 用来存放一些信息:
documents:存放一下用户下载的东东
tmp: Nsuserdefaults存放的目录
app: 项目本身一些所需要的
Library:包含Caches 和 Preferences
Caches:存放程序的支持文件,保证下次启动
Preferences:保存程序的偏好设置
获取各个目录:
根目录:NSHomeDirectory();
获取Documents目录:
1、
NSString *fullPath = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents"];
2、
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsPath = [paths objectAtIndex:0];
获取Caches目录:
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
NSString *cachesDir = [paths objectAtIndex:0];
获取tmp目录:
NSString *tmpDir = NSTemporaryDirectory();
获取app某个文件:
NSString *imagePath = [[NSBundle mainBundle] pathForResource:@”apple” ofType:@”png”];
UIImage *appleImage = [[UIImage alloc] initWithContentsOfFile:imagePath];
获取某个路径下的文件以及文件夹:
NSString *path=@"文件夹路径";
NSFileManager * FileM = [NSFileManager DefaultManager];
NSArray *arr = [FileM directoryContentsAtPath:path];