我正在使用 swift 代码,但没有更改文件扩展名。
这是我的快速代码
let url = NSURL(fileURLWithPath: outputURL.path).deletingPathExtension?.appendingPathExtension("mp3")
最佳答案
您只是创建一个 URL
,然后更改该 URL
。您实际上并未对任何文件进行操作。
要重命名文件,请调用 FileManager.default.moveItem(at:to:)
.将文件 URL 作为第一个参数传递,将具有新名称的文件 URL 作为第二个参数传递。
let newURL = outputURL.deletingPathExtension().appendingPathExtension("mp3")
try FileManager.default.moveItem(at: outputURL, to: newURL)
关于ios - 如何使用swift更改文件扩展名?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54341636/