开发者

filemanager in obj c

in my iPhone app I'm using file manager to check size of file,code is working fine on simulator, but when I run the same app on iphone it is saying file size is zero even though file size is greater than zero, I am using following code:

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(@"_fileSiz开发者_JS百科e:%U",_fileSize); //0 if empty

How can I solve this, can anyone help me? thanx in advance.


Are you sure that the file exists?

Usually if a piece of code that involves files works fine on the simulator but not on the device it is because of wrong filenames. Most simulators run on a case-insensitive filesystem, but the device has a case-sensitive filesystem.

So please check again if you use the correct file path.

You could add something like this to make sure that the file exists:

if (![[NSFileManager defaultManager] fileExistsAtPath:URL2]) {
    NSLog(@"File does not exist");
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜