您好,我正在尝试将文本文件从文档目录复制到位于文档目录中的文件夹名称 Temp
中。
这是我尝试过但不起作用的一些代码。
self.fileManager = [NSFileManager defaultManager];
NSError *error;
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *documentsDirectoryToTemp = [NSString stringWithFormat:@"%@/Temp/",[paths objectAtIndex:0]];
NSString *txtPath = [documentsDirectory stringByAppendingPathComponent:[NSString stringWithFormat:@"%@.txt",tblGetNameToMove.textLabel.text]];
[self.fileManager copyItemAtPath:txtPath toPath:documentsDirectoryToTemp error:&error];
我怎样才能做到这一点?
最佳答案
造成这种情况的原因可能有很多:
首先尝试打印所有路径,如documentsDirectoryToTempn和txtPath,无论是否正确。
第二件事是使用错误变量:
如果(错误) { NSLog("处理时出错:%@",[error localizedDiscription]); }
这样您就可以跟踪确切的问题。
关于ios - 如何从 iOS 文档目录复制文本文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17826923/