Objective c 如何从目标路径获取文件
我不知道如何打开Objective c 如何从目标路径获取文件,objective-c,iphone,nsfilemanager,Objective C,Iphone,Nsfilemanager,我不知道如何打开NSFileManager。 如何在iPhone中打开NSFileManager,并从NSFileManager上传文档,请建议任何简单的方法 如何打开并上载文档,以及如何获取保存文件的路径 我可以在那里找到文件(任何位置) ::编辑:: 那一年我开始编写代码。因此,我不知道NSFileManager显示内容的基本知识: NSLog(@"Documents directory: %@", [fileMgr contentsOfDirectoryAtPath:documentsD
NSFileManager
。
如何在iPhone中打开NSFileManager
,并从NSFileManager
上传文档,请建议任何简单的方法
如何打开并上载文档,以及如何获取保存文件的路径
我可以在那里找到文件(任何位置)
::编辑::
那一年我开始编写代码。因此,我不知道
NSFileManager
显示内容的基本知识:
NSLog(@"Documents directory: %@", [fileMgr contentsOfDirectoryAtPath:documentsDirectory error:&error]);
获取所有文件
//get an instance of the File Manager
NSFileManager *fileManager = [NSFileManager defaultManager];
//we'll list file in the temporary directory
NSString * strPath = NSTemporaryDirectory();
//we'll need NSURL for the File Manager
NSURL *tempDirURL = [NSURL fileURLWithPath:strPath];
//An array of NSURL object representing the path to the file
//using the flag NSDirectoryEnumerationSkipsHiddenFiles to skip hidden files
NSArray *directoryList = [fileManager contentsOfDirectoryAtURL:tempDirURL
includingPropertiesForKeys:nil
options:NSDirectoryEnumerationSkipsHiddenFiles error:nil];
参考:
iPhone的文档目录用于保存数据。我们可以保存一些个人数据,如文件、图像、视频等。文档目录的数据将保留在iPhone的内存中,直到应用程序被强制终止 让我们看一个如何存储一些图像的示例&稍后在iPhone中检索这些图像
// For saving the images in the Document's Directory
-(void)saveImagesInIPhone:(NSData*)imageData withName:(NSString*)imageName
{
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
//Get the docs directory
NSString *documentsDirectoryPath = [paths objectAtIndex:0];
NSString *folderPath = [documentsDirectoryPath stringByAppendingPathComponent:@"IconImages"]; // subDirectory
if (![[NSFileManager defaultManager] fileExistsAtPath:folderPath])
[[NSFileManager defaultManager] createDirectoryAtPath:folderPath withIntermediateDirectories:NOattributes:nil error:nil];
//Add the FileName to FilePath
NSString *filePath = [folderPath stringByAppendingPathComponent:[iconName stringByAppendingFormat:@"%@",@".png"]];
//Write the file to documents directory
[imageData writeToFile:filePath atomically:YES];
}
结果-/var/mobile/Applications/20F869FD-5C61-4900-8CFE-830907731EC9/Documents/Designer0.png
结果:-/var/mobile/Applications/20F869FD-5C61-4900-8CFE-830907731EC9/Documents/Designer0.png您可以获得如下目录路径
-(NSString *)getDBPath
{
//Searching a standard documents using NSSearchPathForDirectoriesInDomains
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentDir = [paths objectAtIndex:0];
NSLog(@"I am in --> getDBPath==%@",paths);
return [documentDir stringByAppendingPathComponent:@"abcd_DB.sqlite"];
}
**如果您使用的是iOS设备-
您可以使用应用程序直接获取数据库
**如果您使用的是模拟器
勾选这个例子:@Mukesh这个对话框能像对话框一样工作吗?我能从中选择文档吗?这可能是一个A-B问题,你能描述一下你的背景细节吗?我不了解你的是,我有所有路径和相关查询,但不像android file manager那样打开,我们可以在其中拍照、文档等。。。不,你不能像android中的filemanager应用那样做。你只能以编程方式执行操作。是的,当然,兄弟,为什么不让我们。
-(NSString *)getDBPath
{
//Searching a standard documents using NSSearchPathForDirectoriesInDomains
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentDir = [paths objectAtIndex:0];
NSLog(@"I am in --> getDBPath==%@",paths);
return [documentDir stringByAppendingPathComponent:@"abcd_DB.sqlite"];
}