NSBundle
is used to access resources within your application itself: that is, everything inside YourApp.app. The documentsDirectory
is a location outside of your app -- it's in the "home directory" which is part of your app sandbox, and which is analogous to your user home directory on the Mac.
进入响应文件夹,
如何进入?如图所示:
或者这样
在“前往文件夹”中输入想前往的文件夹
打开后你所见到的就是沙盒文件夹。
也就是说:你通过打开沙盒进入了沙盒文件夹。
新概念:Bundle
Bundle=.app文件,
下面我们来看一下,Bundle中有什么内容:
点击.app文件,右键打开包内容:
Bundle是下面沙盒中的四个文件中的哪个?
Bundle是四个中的.app文件
打开前,可将沙盒文件夹下的其他文件夹打开看看:
注意:你在这里看到的这个所谓的沙盒文件夹,并不是正真意义上的沙盒。因为他是模拟器模拟的。
所以你可以这样
打开包内容可见:其中我们把Bundle中的这些文件的各自的路径统称为mainBundle;
和沙盒之于应用程序自己数据文件和偏好设置文件,犹mainBundle之于Bundle;
不同的是沙盒和mainBundle区别在于:
mainBundle只关注应用程序,而沙盒也关注应用程序的数据和偏好设置;
//在博主看来mianBundle也是沙盒,不过是沙盒中的沙盒;
- - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
- {
- NSString *homePath = [[NSString alloc] initWithFormat:@"%@",NSHomeDirectory()];
- NSLog(@"%@",homePath);
- NSString *docPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDirectory, YES) objectAtIndex:0];
- NSLog(@"%@",docPath);
- NSString *tmpPath = NSTemporaryDirectory();
- NSLog(@"%@",tmpPath);
- //偏好设置
- [[NSUserDefaults standardUserDefaults] setFloat:23.4 forKey:@"float"];
- NSString *appPath = [[NSBundle mainBundle] resourcePath];
- NSLog(@"%@",appPath);
- NSString *bundlePath = [[NSBundle mainBundle ] bundlePath];
- NSLog(@"%@",bundlePath);
- NSString *execPath = [[NSBundle mainBundle ] executablePath];
- NSLog(@"%@",execPath);
- NSString *filePath = [[NSBundle mainBundle ] pathForResource:@"Chen_Yilong" ofType:@"rtf"];
- NSLog(@"%@",filePath);
- NSString *file = [NSString stringWithContentsOfFile:filePath encoding:NSUTF8StringEncoding error:nil];
- NSLog(@"%@",file);
- return YES;
- }
- /Users/rjxyrjxy/Library/Application Support/iPhone Simulator/5.1/Applications/66504B82-7E7F-4FE4-8871-81348A4D0DD4
- /Users/rjxyrjxy/Library/Application Support/iPhone Simulator/5.1/Applications/66504B82-7E7F-4FE4-8871-81348A4D0DD4/Documents
- /var/folders/fd/61_st6k93vbcnn7z7kkmcdh40000gn/T/
- /Users/rjxyrjxy/Library/Application Support/iPhone Simulator/5.1/Applications/66504B82-7E7F-4FE4-8871-81348A4D0DD4/HomeDictionaryTest.app
- /Users/rjxyrjxy/Library/Application Support/iPhone Simulator/5.1/Applications/66504B82-7E7F-4FE4-8871-81348A4D0DD4/HomeDictionaryTest.app
- /Users/rjxyrjxy/Library/Application Support/iPhone Simulator/5.1/Applications/66504B82-7E7F-4FE4-8871-81348A4D0DD4/HomeDictionaryTest.app/HomeDictionaryTest
- Users/rjxyrjxy/Library/Application Support/iPhone Simulator/5.1/Applications/66504B82-7E7F-4FE4-8871-81348A4D0DD4/HomeDictionaryTest.app/Chen_Yilong.rtf
- {\rtf1\ansi\ansicpg936\cocoartf1138\cocoasubrtf470
- {\fonttbl}
- {\colortbl;\red255\green255\blue255;}
- \paperw11900\paperh16840\margl1440\margr1440\vieww10800\viewh8400\viewkind0
- }