文件无法打开 - 但确实存在 - swift 3

时间:2016-12-13 00:38:13

标签: swift file filesystems swift3 ios10

我正在使用以下代码将视频录制到文件中:

print(documentsPath)
            //var/mobile/Containers/Data/Application/FFB207E7-36CC-4C53-A2E2-5FADC7C23A18/Documents/gymnastVideos/test.mp4
        let filePath = NSURL(fileURLWithPath: documentsPath)
        videoFileOutput.startRecording(toOutputFileURL: filePath as URL!, recordingDelegate: recordingDelegate)

并验证该文件是否存在,但是,当我尝试打开文件以检查是否有任何内容保存时,我返回错误。代码:

var documentsPath = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true)[0]
        documentsPath.append("/gymnastVideos")
        let filePath = URL(fileURLWithPath: documentsPath)

        do {
            let directoryContents = try FileManager.default.contentsOfDirectory(at: filePath, includingPropertiesForKeys: nil, options: [])
            print(directoryContents)
            print("!")
        } catch let error as NSError {
            print(error.localizedDescription)
                //The file “gymnastVideos” couldn’t be opened.
            print("!!")
        }

为什么我无法打开文件,我需要在代码中更改哪些内容才能打开文件?

0 个答案:

没有答案