#import "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
#pragma mark ----第一種獲取文件夾地址的方式----
?????? //NSDocumentDirectory:表示獲取Document文件夾的地址
????? //NSUserDomainMask:表示用戶的主目錄
?? ?? //參數(shù)三:表示展開....的地址,設(shè)置為Yes表示為完整的路徑
????? //NSSearchPathForDirectoriesInDomains獲取的是一個數(shù)組,數(shù)組只有一個元素,所以直接賦下標(biāo)為0;???
NSString *documentPathStr =[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
NSLog(@"%@",documentPathStr);
//獲取Library文件的路徑
NSString *libraryPathStr = [NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask, YES) objectAtIndex:0];
NSLog(@"%@",libraryPathStr);
#pragma mark ----第二種獲取沙盒主路經(jīng)的地址------
//step1:獲取沙盒主路經(jīng)地址
NSString *homePathStr = NSHomeDirectory();
NSLog(@"homePathStr =====%@",homePathStr);
//step2:在沙盒主路經(jīng)后面拼接Documents ,拼接出來documents文件夾的路徑
NSString *document1PathStr = [homePathStr stringByAppendingPathComponent:@"Documents"];
NSLog(@"homePathStr =====%@",document1PathStr);
//step2:在沙盒主路經(jīng)后面拼接想要獲取的全路徑
NSString *cachePathStr = [homePathStr stringByAppendingPathComponent:@"Library/Caches"];
NSLog(@"cachePathStr =====%@",cachePathStr);
#pragma mark ----特例:獲取tmp路徑------
NSString *tmpPathStr = NSTemporaryDirectory();
NSLog(@"tmpPathStr === %@",tmpPathStr);
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end