- int main(int argc, const char * argv[]) {
- @autoreleasepool {
-
- //NSHomeDirectory();获取根目录
- NSString *SanBoxPath=NSHomeDirectory();
- //获取沙盒中的Documents目录 NSDocumentDirectory表示返回绝对路径是Documents目录
- //NSUserDomainMask 查找的是用户宿主目录
- //YES 是否显示全部目录
- NSArray *array= NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
- NSLog(@"%@",array);
- //取出路径
- NSString *filePath=[array lastObject];
- //拼接路径
- NSString *str=
- [filePath stringByAppendingPathComponent:@"Preferences/1.txt"];
- NSString *str2=@"abc";
- //把字符串写入路径中
- BOOL b=[str2 writeToFile:str atomically:YES encoding:NSUTF8StringEncoding error:nil];
- NSLog(@"%d",b);
-
- }
- return 0;
- }
复制代码
|
|