swift 获取文件大小

it2022-05-05  123

//获取文件大小 func getSize(url: URL)->UInt64 { var fileSize : UInt64 = 0 do { let attr = try FileManager.default.attributesOfItem(atPath: url.path) fileSize = attr[FileAttributeKey.size] as! UInt64 let dict = attr as NSDictionary fileSize = dict.fileSize() } catch { print("Error: \(error)") } return fileSize }

获取之前最好先判断下文件是否存在

FileManager.default.fileExists(atPath: path)

  

转载于:https://www.cnblogs.com/kunH/p/7283233.html

相关资源:IOS获取缓存文件的大小并清除缓存文件的方法

最新回复(0)