//访问沙盒路径
//1.Home主目录,里面有 :Documents.Library.temp 和一个应用程序
// NSLog(@"Home:%@",NSHomeDirectory());
//2,Documents
NSString *DocumentsPath=NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES)[0];
NSLog(@"Documents:%@",DocumentsPath);
//3.Library
NSString *LinraryPath=NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask, YES)[0];
NSLog(@"Library:%@",LinraryPath);
//4.temp
NSLog(@"temp:%@",NSTemporaryDirectory());
//5.caches
NSString *cachesPath=NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES)[0];
NSLog(@"caches:%@",cachesPath);
//6.user
NSString *userPath=NSUserName();
NSLog(@"user:%@",userPath);
//7.NSBoundle
NSString *boundle=[[NSBundle mainBundle]pathForResource:@"89" ofType:@"png"];
NSLog(@"bundle:%@",boundle);
NSString写入
//简单文件写入,
//NSString写入
//1.写入的路径
NSString *doucmentPath=NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES)[0];
NSLog(@"%@",doucmentPath);
//2.拼接文件路径
NSString *filePath=[doucmentPath stringByAppendingString:@"/myText.txt"];
//3.准备写入的内容
NSString *content=@"Hello World.";
//4.写入
[content writeToFile:filePath atomically:YES encoding:NSUTF8StringEncoding error:nil];
//5.读取
NSString *readString=[NSString stringWithContentsOfFile:filePath encoding:NSUTF8StringEncoding error:nil];
NSLog(@"readString:%@",readString);
NSArray写入
//NSArray写入
//1.获取doucuments路径
//2.拼接文件路径
NSString *arrayFile=[doucmentPath stringByAppendingString:@"/array.plist"];
//3.准备内容
NSArray *array=@[@"123",@"456,",@"780"];
//4.写入
[array writeToFile:arrayFile atomically:YES];
//读取
NSArray *readArray=[NSArray arrayWithContentsOfFile:arrayFile];
NSLog(@"readArray:%@",readArray);
NSDictionary写入
//NSDictionary写入
//1.获取doucuments路径
//2.拼接文件路径
NSString *dicFile=[doucmentPath stringByAppendingString:@"/dic.plist"];
//3.准备内容
NSDictionary *dic=[NSDictionary dictionaryWithObject:@"8888" forKey:@"a"];
//4.写入
[dic writeToFile:dicFile atomically:YES];
//读取
NSDictionary *readDic=[NSDictionary dictionaryWithContentsOfFile:dicFile];
NSLog(@"readDic:%@",readDic);