首页 > 解决方案 > iOS Swift:如何从我的文档目录文件创建 .zip 文件

问题描述

在我的应用程序中,想要捕获日志消息,并将日志消息写入文本文件,然后压缩附加的文本文件。

这是我的代码:

let file = "APPLog.txt" //this is the file. we will write to and read from it
        let text = "MyLog messages"//just a text
        if let dir = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first {
            let fileURL = dir.appendingPathComponent(file)
            //writing
            do {
                try text.write(to: fileURL, atomically: false, encoding: .utf8)
            }
            catch {/* error handling here */}
            //reading
            do {
                let readtxt = try String(contentsOf: fileURL, encoding: .utf8)
                print("readtxt",readtxt)
            }
            catch {/* error handling here */}
        }

在文档目录“APPLog.txt”中创建此文本文件。我怎样才能压缩这个文本文件和附加的思想邮件。帮我。提前谢谢。

标签: swiftdictionaryzipdocumentunzip

解决方案


推荐阅读