ios文件存放路径、文件目录、缓存文件夹

/*

documents,tmp,app,Library(NSHomeDirectory()),手动保存的文件在documents文件里

Nsuserdefaults保存的文件在tmp文件夹里

1.documents:用于储存用户数据或者其他应该定期备份的信息

2.AppName.app:应用程序的包目录,包含程序的本身,无法对这个目录的内容进行修改,因为程序有签名

3.library目录:(Caches

和 Preferences)

Preferences

目录:包含应用程序的偏好设置文件。您不应该直接创建偏好设置文件,而是应该使NSUserDefaults类来取得和设置应用程序的偏好.

Caches

目录:用于存放应用程序专用的支持文件,保存应用程序再次启动过程中需要的信息

4.tmp

目录:这个目录用于存放临时文件,保存应用程序再次启动过程中不需要的信息。

*/

// 第一种方式:获取家目录路径的函数:

NSString *homeDir = NSHomeDirectory();

NSLog(@"%@",homeDir);

//

第二种方式:获取Documents目录路径的方法:

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,

NSUserDomainMask,

YES);

NSString *docDir = [paths

objectAtIndex:0];

NSLog(@"%@",docDir);

//

第三种方式:获取Caches目录路径的方法:

NSArray *paths1 = NSSearchPathForDirectoriesInDomains(NSCachesDirectory,

NSUserDomainMask,

YES);

NSString *cachesDir = [paths1

objectAtIndex:0];

NSLog(@"%@",cachesDir);

//

第四种方式:获取tmp目录路径的方法:

NSString *tmpDir = NSTemporaryDirectory();

NSLog(@"%@",tmpDir);

//

第五种方式:获取应用程序程序包中资源文件路径的方法,例如获取程序包中一个图片资源(apple.png)路径的方法:

NSString *Path = [[NSBundle

mainBundle] pathForResource:@""

ofType:@"png"];

UIImage *Image = [[UIImage

alloc] initWithContentsOfFile:Path];

NSLog(@"%@",Image);

[an error occurred while processing the directive]
Copyright © 2088 时代中心网 - 经典游戏活动回顾 All Rights Reserved.
友情链接