iOS下的文件和文件夹的隐藏



在实际的开发过程中,有些情况下,需要将文件或者文件夹隐藏起来,不让用户看到。

比如说在打开documents的共享的时候,又不希望用户通过itunes看到的情况下。

隐藏文件,其实是利用unix文件系统的特性,在文件命名的时候加了一个点“.”实现了隐藏文件的效果。

例如:创建了一个隐藏文件夹hideDir,之后在里边保存了一个文件passwrod.txt

代码如下:

[plain]  view plain copy
  1. NSString* cachesPath = [NSSearchPathForDirectoriesInDomains(NSCachesDirectory,NSUserDomainMask,YES)objectAtIndex:0];  
  2.   NSString* hideDirpath = [NSString stringWithFormat:@"%@%@/", cachesPath,@"/.hideDir"];  
  3.   NSFileManager* fileManager = [NSFileManager defaultManager];  
  4.   BOOL isDir;  
  5.   if (![fileManager fileExistsAtPath:hideDirpath isDirectory:&isDir]) {  
  6.       if (![fileManager createDirectoryAtPath:hideDirpath withIntermediateDirectories:YES attributes:nil error:nil]) {  
  7.           NSLog(@"创建文件目录失败!");  
  8.       }  
  9.   }  
  10.     
  11.   NSString* filepath = [NSString stringWithFormat:@"%@%@",hideDirpath, @"password.txt"];  
  12.   NSDictionary * dic = [NSDictionary dictionaryWithObject:@"pwd1"forKey:@"pwd"];  
  13.   [dic writeToFile:filepath atomically:YES];  
  14.     
  15.   //验证一下,是否保存成功  
  16.   NSDictionary * context= [NSDictionary dictionaryWithContentsOfFile:filepath];  
  17.   NSLog(@"context=%@",context);


转自:http://blog.csdn.net/yuquan0821/article/details/7565976






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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值