iphone中获取文件路径的4种方法

 

1,document 中的路径  最麻烦的一种:

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);

    NSString *documentsDirectory = [paths objectAtIndex:0];

    NSString *writableDBPath = [documentsDirectory stringByAppendingPathComponent:filename;    

 

 本人自写自用的宏

2,#define ABS_FILE_PATH(FILE_NAME) [NSString stringWithFormat:@"%@/Documents/%@", NSHomeDirectory(),FILE_NAME]

 

 

3获取程序application package下的文件路径:

#define PACKAGE_FILE_PATH(FILE_NAME) [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:FILE_NAME]

 

4NSString* filePath = [[NSBundle mainBundle] pathForResource:@"fileName" ofType:@"fileType(txt...html..)"];

原文地址:https://www.cnblogs.com/moshengren/p/1855935.html