swift - 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”中创建此文本文件。我怎样才能压缩这个文本文件和附加的思想邮件。帮我。提前谢谢。
解决方案
推荐阅读
- php - 连接行上的 db 值
- json - Azure 数据工厂 V2 - 解析 JSON HTTP GET 数据集
- node.js - Nodejs/Express 将参数传递给 ejs 查看 res.render vs window.location.replace
- elasticsearch - 我需要一个用于 elasticsearch 的阿拉伯语分析器
- excel - Excel - 如何从两个单独的查找和值之间查找输出
- android - Android - Kotlin - 如何克服按钮的最小宽度限制?
- python - 构建简单神经网络时的 Python 代码
- ios - 如何在 Swift 中将数组值作为单独的参数传递?
- r - 用 tidyverse 找到最大值
- r - 将所有观察结果的 Shapley 原因代码附加到整个数据