// 获得根目录的方式
NSString *homePath = NSHomeDirectory();
NSLog(@"%@",homePath);
// 获得Documents目录的方式
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *DocumentPath = [paths firstObject];
NSLog(@"%@",DocumentPath);
// 获得library/Caches目录的方法
NSArray *paths2 = NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask, YES);
NSString *libraryPath = [paths2 lastObject];
NSLog(@"%@",libraryPath);
NSArray *paths3 = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
NSString *cachesPath = [paths3 firstObject];
NSLog(@"cachesPath:%@",cachesPath);
// 获得临时文件tmp目录的方法
NSString *tempPath = NSTemporaryDirectory();
NSLog(@"%@",tempPath);
本文介绍了如何使用Objective-C在iOS应用中获取各种重要的文件路径,包括根目录、Documents目录、library/Caches目录以及临时文件tmp目录的方法。
1186

被折叠的 条评论
为什么被折叠?



