我们的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中加载,我们还可以在其他我们需要的时候 加载的地方哦