本文介绍了我正在尝试查找文件大小.但我的长度等于零的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试查找文件大小.

I'm trying to find a file size.

 NSFileHandle *output = [NSFileHandle fileHandleForWritingAtPath:self.finalPath];
//seek to begin of the file
[output seekToFileOffset:0];
NSData *mydata = [output availableData];
NSLog(@"length: %d", [mydata length]);

但我的长度等于零.为什么?

But my length is equl to zero. Why?

推荐答案

availableData 用于读取文件.如果您只想了解文件的大小,实际上不必打开它.只需像这样使用 NSFileManager :

availableData is for reading files. If you just want to find out the size of a file, you don't actually have to open it. Just use NSFileManager like this:

NSDictionary *attributes = [[NSFileManager defaultManager] attributesOfItemAtPath:self.finalPath error:NULL];
unsigned long long fileSize = [attributes fileSize]; // in bytes

这篇关于我正在尝试查找文件大小.但我的长度等于零的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 18:57
查看更多