【问题标题】:How to read download file from path in ios如何从ios中的路径读取下载文件
【发布时间】:2015-01-29 03:00:48
【问题描述】:

我已尝试下载和阅读文件 (pdf/epub)。 我已经实现了下载并将文件保存在下面的路径中。

下载路径为-文件路径

/Users/apple/Library/Application Support/iPhone Simulator/7.1/Applications/B5C69537-DBAA-45DA-BDF3-84D0F038378D/Documents/3471.epub

但我无法从同一路径读取。我正在使用以下编码来读取文件路径。

NSString *testpath =[[NSBundle mainBundle] pathForResource:@"3471" ofType:@"epub"];

【问题讨论】:

  • 请发布更多代码,即您如何从该路径读取文件
  • 请参考以下Link

标签: ios objective-c iphone xcode5


【解决方案1】:

NSBundle mainBundle 用于添加到项目文件夹中的文件。

如果您需要查找任何已下载文件保存到文档文件夹的方法,请尝试

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,
                                                     NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *testpath = [documentsDirectory stringByAppendingPathComponent:filename];

【讨论】:

  • 亲爱的 Nazik,我使用了您的代码,并且能够在 NSString 变量中获取文件的路径,但我无法读取文件,请在下面找到代码。 NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); NSString *documentsDirectory = [paths objectAtIndex:0]; NSString *testpath = [documentsDirectory stringByAppendingPathComponent:@"3471.epub"]; NSLog(@"测试路径 %@",testpath); if( [za UnzipOpenFile:testpath]){ }
  • 当你 NSLog 测试路径时你得到了什么?
  • @Saravanan,当你 NSLog 测试路径时,你得到了什么?
猜你喜欢
  • 2018-01-07
  • 1970-01-01
  • 2020-01-22
  • 1970-01-01
  • 1970-01-01
  • 2023-03-21
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多