在我的iPhone应用程序中,我使用以下代码来查找文件的大小.即使该文件存在,我看到的大小为零.谁能帮我?提前致谢.
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *URL = [documentsDirectory stringByAppendingPathComponent:@"XML/Extras/Approval.xml"];
NSLog(@"URL:%@",URL);
NSError *attributesError = nil;
NSDictionary *fileAttributes = [[NSFileManager defaultManager] attributesOfItemAtPath:URL error:&attributesError];
int fileSize = [fileAttributes fileSize];
Run Code Online (Sandbox Code Playgroud) 我在用
UIImagePickerControllerDelegate,
UINavigationControllerDelegate,
UIPopoverControllerDelegate
Run Code Online (Sandbox Code Playgroud)
这些代表从我的画廊或我的相机中选择图像.那么,如何在选择图像后获得图像文件大小?
我想用这个:
let filePath = "your path here"
var fileSize : UInt64 = 0
do {
let attr : NSDictionary? = try NSFileManager.defaultManager().attributesOfItemAtPath(filePath)
if let _attr = attr {
fileSize = _attr.fileSize();
print(fileSize)
}
} catch {
}
Run Code Online (Sandbox Code Playgroud)
但是在这里我需要一条路径,但是如果没有路径,我只能通过图像文件获得?