首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >obj c中的filemanager

obj c中的filemanager
EN

Stack Overflow用户
提问于 2011-03-24 19:52:29
回答 1查看 331关注 0票数 0

在我的iPhone应用程序中,我使用文件管理器检查文件的大小,代码在模拟器上运行良好,但当我在iphone上运行相同的应用程序时,它显示文件大小为零,即使文件大小大于零,我使用的代码如下:

代码语言:javascript
复制
NSArray *paths1 = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory1 = [paths1 objectAtIndex:0];
documentsDirectory1 = [documentsDirectory1 stringByAppendingPathComponent:@"XML"];
NSString * szDestPath1 = [documentsDirectory1 stringByAppendingPathComponent:@"Extras"];
NSString *URL2 = [szDestPath1 stringByAppendingPathComponent:@"config.xml"];


NSLog(@"%@",URL2);
NSError *attributesError = nil;
NSDictionary *fileAttributes = [[NSFileManager defaultManager] attributesOfItemAtPath:URL2 error:&attributesError];

int _fileSize = [fileAttributes fileSize];

NSLog(@"_fileSize:%U",_fileSize); //0 if empty

我该如何解决这个问题,有人能帮我吗?提前谢谢。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2011-03-24 20:47:39

您确定文件存在吗?

通常,如果涉及文件的一段代码在模拟器上工作正常,但在设备上却不能正常工作,那是因为文件名错误。大多数模拟器运行在不区分大小写的文件系统上,但设备具有区分大小写的文件系统。

因此,请再次检查您是否使用了正确的文件路径。

您可以添加类似以下内容的内容以确保该文件存在:

代码语言:javascript
复制
if (![[NSFileManager defaultManager] fileExistsAtPath:URL2]) {
    NSLog(@"File does not exist");
}
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/5418668

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档