[新手学IOS]第六天:如何获得app的doucuments和tmp的路径目录(17431)

我们的app都运行在虚拟机中,那么虚拟机中加载的 文件以及产生的文件在哪里显示呢?

我们关注的两个文件夹是doucuments 和 tmp .那么如何获得这两个路径以及 路径下文件的创建呢 ?

看看如下代码:

- (void)viewDidLoad
{
    [super viewDidLoad];
    
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentationDirectory, NSUserDomainMask, YES);
    //NSDocumentationDirectory 表示我们正在查找的documents的路径
    //
    NSLog(@"%@",paths);
    //
    NSString *documentsDirectory = [paths objectAtIndex:0];
    NSLog(@"%@",documentsDirectory);
    //上述documentsDirectory  得到了我们的docoument的目录,如果我们想要确切名字的文件,可使用如下代码:
    
    NSString *filesPath = [documentsDirectory stringByAppendingPathComponent:@"hello.text"];
    NSLog(@"%@",filesPath);
    /*
     2013-11-25 16:57:09.930 第四章-关于控件的使用[1264:a0b] (
     "/Users/len/Library/Application Support/iPhone Simulator/7.0/Applications/43F0A153-D36D-4A62-821E-C1D6C0644F8B/Library/Documentation"
     )
     2013-11-25 16:57:09.931 第四章-关于控件的使用[1264:a0b] /Users/len/Library/Application Support/iPhone Simulator/7.0/Applications/43F0A153-D36D-4A62-821E-C1D6C0644F8B/Library/Documentation
     2013-11-25 16:57:09.932 第四章-关于控件的使用[1264:a0b] /Users/len/Library/Application Support/iPhone Simulator/7.0/Applications/43F0A153-D36D-4A62-821E-C1D6C0644F8B/Library/Documentation/hello.text
     */
    
    
    //获取 tmp的路径
    
    NSString *tempPath = NSTemporaryDirectory();
    
    NSString *tempfilePath = [tempPath stringByAppendingPathComponent:@"tempFile.text"];
    
    NSLog(@"%@",tempfilePath);
    //2013-11-25 17:00:18.947 第四章-关于控件的使用[1283:a0b] /Users/len/Library/Application Support/iPhone Simulator/7.0/Applications/43F0A153-D36D-4A62-821E-C1D6C0644F8B/tmp/tempFile.text
    
    
	// Do any additional setup after loading the view, typically from a nib.
}

当然,不是说这个文件夹的目录操作必须在viewdidload中加载,我们还可以在其他我们需要的时候 加载的地方哦

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值