![ios – 移动文件并覆盖[复制],第1张 ios – 移动文件并覆盖[复制],第1张](/aiimages/ios+%E2%80%93+%E7%A7%BB%E5%8A%A8%E6%96%87%E4%BB%B6%E5%B9%B6%E8%A6%86%E7%9B%96%5B%E5%A4%8D%E5%88%B6%5D.png)
我正在尝试移动文件,即使已经存在具有相同名称的文件.
NSfileManager().moveItemAtURL(location1,toURL: location2)
NSfileManager的方法moveItemAtURL是否有覆盖选项?如何替换现有文件?
解决方法 您始终可以检查文件是否存在于目标位置.如果是,请删除它并移动您的项目.
斯威夫特2.3
let filemgr = NSfileManager.defaultManager()if !filemgr.fileExistsAtPath(location2) { do { try filemgr.moveItemAtURL(location1,toURL: location2) } catch { }}else{ do { try filemgr.removeItemAtPath(location2) try filemgr.moveItemAtURL(location1,toURL: location2) } catch { }} 斯威夫特3
try? fileManager.default.removeItem(at: location2)try fileManager.default.copyItem(at: location1,to: location2)总结
以上是内存溢出为你收集整理的ios – 移动文件并覆盖[复制]全部内容,希望文章能够帮你解决ios – 移动文件并覆盖[复制]所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)