文件路径两种获取方式
来源:互联网 发布:暴力破解rar密码软件 编辑:程序博客网 时间:2024/05/18 08:24
第一种类型:文件在工程中
NSString *path=[[NSBundle mainBundle]pathForResource:@"chat" ofType:@"plist"];
chatArray=[[NSArray alloc]initWithContentsOfFile:path];
1
2
第二种类型:文件在模拟器后台
//方法一
NSString *documents = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents"];
NSString *path = [documents stringByAppendingPathComponent:@"person.arch"];
//方法二
-(NSString *)getDBpath{
//获取documents目录
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory=[paths objectAtIndex:0];
NSString *dbPath = [documentsDirectory stringByAppendingPathComponent:@"data.sqlite"];
NSLog(@"db path:%@",dbPath);
return dbPath;
}
//方法三,也是最常用的方法
-(NSString *)getPlishpathbyname:(NSString*)name
{
// 首先获取根目录的路径
NSString *documentspath=[NSHomeDirectory()stringByAppendingPathComponent:@"Documents"];
// 创建一个name.plist(USER.plist)的文件
// 将传入字符为名字的文件路径找出来,拼接在根目录后面,传入的文件名字用方法实现[NSStrin stringWithFormat:@"%@.plist",name]
NSString *filepath=[documentspath stringByAppendingPathComponent:[NSString stringWithFormat:@"%@.plist",name]];
NSLog(@"%@",filepath);
return filepath;
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
NSString *path=[[NSBundle mainBundle]pathForResource:@"chat" ofType:@"plist"];
chatArray=[[NSArray alloc]initWithContentsOfFile:path];
1
2
第二种类型:文件在模拟器后台
//方法一
NSString *documents = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents"];
NSString *path = [documents stringByAppendingPathComponent:@"person.arch"];
//方法二
-(NSString *)getDBpath{
//获取documents目录
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory=[paths objectAtIndex:0];
NSString *dbPath = [documentsDirectory stringByAppendingPathComponent:@"data.sqlite"];
NSLog(@"db path:%@",dbPath);
return dbPath;
}
//方法三,也是最常用的方法
-(NSString *)getPlishpathbyname:(NSString*)name
{
// 首先获取根目录的路径
NSString *documentspath=[NSHomeDirectory()stringByAppendingPathComponent:@"Documents"];
// 创建一个name.plist(USER.plist)的文件
// 将传入字符为名字的文件路径找出来,拼接在根目录后面,传入的文件名字用方法实现[NSStrin stringWithFormat:@"%@.plist",name]
NSString *filepath=[documentspath stringByAppendingPathComponent:[NSString stringWithFormat:@"%@.plist",name]];
NSLog(@"%@",filepath);
return filepath;
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
0 0
- 文件路径两种获取方式
- 根据路径获取文件的两种方式
- JAVA WEBl两种获取路径方式
- 两种获取文件路径的方法
- 两种方式获取文件路径及保存属性列表plist
- EL 与jsp 两种方式获取请求路径
- java文件路径获取方式
- 关于plist文件路径的两种读写方式
- 获取Java文件路径的两种方法
- 获取沙盒文件路径的两种方法
- 获取文件存储属性的两种方式
- java中获取文件路径的几种方式
- java中获取文件路径的几种方式
- java中获取文件路径的几种方式
- java中获取文件路径的几种方式
- java中获取文件路径的几种方式
- Java中获取文件路径的几种方式
- Java中获取文件路径的几种方式
- Android面试题汇总
- 多次请求后tomcat网页假死
- 02 bootstrap "modal : is not a function"
- Mac 查看端口占用情况
- polya计数回顾
- 文件路径两种获取方式
- Git使用总结
- Python+Requests抓取中文乱码改进方案
- Android:开源框架xutils介绍之 HttpUtils
- Maven Dependency 丢失
- C++primer学习:类模板(2)类模板:模板参数,成员模板和控制实例化
- H5formData无刷新上传文件
- java中堆和栈的区别
- Can't create a new thread (errno 11) 解决办法 mysql无法连接