Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Objective c copyItemAtPath:toPath:错误:正在返回否_Objective C_Macos_Nsurl_Nsfilemanager_File Copying - Fatal编程技术网

Objective c copyItemAtPath:toPath:错误:正在返回否

Objective c copyItemAtPath:toPath:错误:正在返回否,objective-c,macos,nsurl,nsfilemanager,file-copying,Objective C,Macos,Nsurl,Nsfilemanager,File Copying,我正在读的这一章是关于NSFileManager,作者说创建一个名为testFile的空文件。testFile与main.m位于同一文件夹下。我没有创建newfile。我无法复制测试文件,它返回了2个和一个NSLog说@“无法复制文件”。我试图将toPath的参数设置为:as@/Users/el/Desktop/prog/prog/newfile“ 第二条路径也必须是绝对路径 [fm copyItemAtPath: @"/Users/el/Desktop/prog/prog/testFile"

我正在读的这一章是关于
NSFileManager
,作者说创建一个名为
testFile
的空文件。
testFile
main.m
位于同一文件夹下。我没有创建
newfile
。我无法复制
测试文件
,它返回了2个
和一个
NSLog
@“无法复制文件”
。我试图将toPath的参数设置为:as
@/Users/el/Desktop/prog/prog/newfile“


第二条路径也必须是绝对路径

[fm copyItemAtPath: @"/Users/el/Desktop/prog/prog/testFile" toPath: @"/Users/el/Desktop/prog/prog/newFile" error: NULL];

注意:您应该使用基于
NSURL
的方法,而不是基于
NSString
的方法。

对不起,
[fm copyItemAtPath:@/Users/el/Desktop/prog/prog/testFile”toPath:@“/Users/el/Desktop/prog/prog/newfile”错误:NULL]
没有其他建议吗?哦,我只是在遵循作者的指示。也许他稍后会查看NSURL
。@Emily你绝对确定这条路径存在,并且你有权在其中写入内容吗?我不知道否则为什么会失败。如果您尝试URL变量:
[fm copyitematural:[NSURL fileURLWithPath:@”/Users/el/Desktop/prog/prog/testFile“]tour:[NSURL fileURLWithPath:@”/Users/el/Desktop/prog/prog/newFile”]error:nil]
?@Emily您也可以做的是请求错误信息,比如:
NSError*error=nil;[fm copyItemAtURL:(…)toURL:(…)错误:&错误];if(错误)NSLog(错误)[fm copyItemAtPath: @"/Users/el/Desktop/prog/prog/testFile" toPath: @"/Users/el/Desktop/prog/prog/newFile" error: NULL];