尝试复制文件时出错 [英] Error when trying to copy file

查看:115
本文介绍了尝试复制文件时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用NSFileManager将临时文件复制到另一个位置。但是,它失败并抱怨其中一个文件不存在。

I'm trying to copy a temp file to another location using NSFileManager. However it's failing and complaining that one of the files does not exists.

 //Copy temp file
    NSError *error;
    BOOL exists = [fileManager fileExistsAtPath:chapterFileTemp];
    exists = [fileManager fileExistsAtPath:chapterFile];

    [fileManager copyItemAtURL:[NSURL fileURLWithPath:chapterFileTemp]
                         toURL:[NSURL fileURLWithPath:chapterFile]
                         error:&error];

    //Delete temp path
    [fileManager removeItemAtURL:[NSURL fileURLWithPath:chapterFileTemp] error:&error];

复制操作时出现错误

(错误域= NSCocoaErrorDomain代码= 260操作无法完成。(可可错误260。) UserInfo = 0x1c5190b0 {NSFilePath = / var / mobile / Applications / 57727CCD-88AD-4D84-8C78-EA8100645C9B / Documents /119/myFileTemp.temp,NSUnderlyingError=0x1c527960操作无法完成。没有这样的文件或目录。

(Error Domain=NSCocoaErrorDomain Code=260 "The operation couldn’t be completed. (Cocoa error 260.)" UserInfo=0x1c5190b0 {NSFilePath=/var/mobile/Applications/57727CCD-88AD-4D84-8C78-EA8100645C9B/Documents/119/myFileTemp.temp, NSUnderlyingError=0x1c527960 "The operation couldn’t be completed. No such file or directory").

现在,第一个BOOL返回YES,第二个BOOL返回NO。

Now the first BOOL returns YES, and the second one NO. Which is expected.

失败的原因可能是什么

谢谢。

推荐答案

当目标路径缺少目录时,这是可能的。
确保要复制源文件的位置包含所有必需的目录。

This is possible when the destination path is missing the directory. Make sure that the place at which you want to copy the source file is containing all required directory.

这篇关于尝试复制文件时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆