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..)"];

posted @ 2010-10-19 22:29  苏瑞强  阅读(1718)  评论(0编辑  收藏  举报