//iOS沙盒中一共有4个文件夹:Documents/tmp/app/Library
---安装目录(home),只读
---Documents:长期放用户文件或文件夹,rw
---A.app:mainBundle,存放可执行文件和资源文件,r
---tmp:存放临时文件,rw
---Library
---Caches:存放缓存文件,rw
- (NSString *)stringByAppendingPathComponent:(NSString *)str;
stringByAppendingPathComponent:字符串附加路径要素
NSArray *NSSearchPathForDirectoriesInDomains(NSSearchPathDirectory directory, NSSearchPathDomainMask domainMask, BOOL );
NSSearchPathForDirectoriesInDomains:在域名里寻找目录的路径
- (BOOL)writeToFile:(NSString *)path atomically:(BOOL)useAuxiliaryFile encoding:(NSStringEncoding)enc error:(NSError **)error;
useAuxiliaryFile:用附加的文件 NSUTF8StringEncoding:中文编码
NSString *home = NSHomeDirectory();
NSLog(@"%@",home); //获取安装目录home的路径
NSString *documents = [home stringByAppendingPathComponent:@"Documents"];
NSLog(@"XXX%@",documents); //添加Documents,获取Documents目录的路径
//stringByAppendingPathComponent:字符串附加路径要素
NSArray *array = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
//NSSearchPathForDirectoriesInDomains:在域名里寻找目录的路径,NSUserDomainMask:用户安装目录;把Caches的目录的地址存入数组
NSLog(@"---%@",array);
// NSString *doc2 = [array objectAtIndex:0];
NSString *doc2 = [array firstObject]; //将数组首元素赋给doc2
NSLog(@"+++%@",doc2);
NSString *tmp = NSTemporaryDirectory();
NSLog(@"%@",tmp); //获取Temporary目录的路径
NSString *name = @"戴维营";
NSString *path = [documents stringByAppendingPathComponent:@"test1.plist"];
//在documents目录下添加文件test1.plist
[name writeToFile:path atomically:YES encoding:NSUTF8StringEncoding error:nil];
//将name写入文件,NSUTF8StringEncoding:中文编码
NSLog(@"%@",path);
//获取当前程序中的资源文件路径
NSString *dbPath = [[NSBundle mainBundle] pathForResource:@"testDB" ofType:@"db"];
NSLog(@"%@",dbPath);