gpt4 book ai didi

nativescript - 你如何附加到 Nativescript 中的文件?

转载 作者:行者123 更新时间:2023-12-02 01:12:15 29 4
gpt4 key购买 nike

你如何附加到文件而不是覆盖它?

file-system module文档解释了如何写入文件:

The following example writes some text to a file. It will create a new file or overwrite an existing file.


var documents = fs.knownFolders.documents();
var file = documents.getFile("Test_Write.txt");

// Writing text to the file.
file.writeText("Something")
.then(function () {
// Succeeded writing to the file.
}, function (error) {
// Failed to write to the file.
});

我的最终目标是在 nativescript 应用程序运行时将日志文件写入磁盘。将日志文件的内容读入内存,附加新的日志消息,然后将其全部写回文件,效率太低了。

更新:
最终登录到 sqlite 数据库。这有一些优点和缺点,但对于其他试图解决类似问题的人来说,这是另一个尝试的方向。

最佳答案

NativeScript 目前不为其文件系统模块提供 appendFile 函数。
引用:https://github.com/NativeScript/NativeScript/issues/4462
可以在此处找到 appendFile 的示例实现(仅文本):https://github.com/EddyVerbruggen/nativescript-node/blob/dc93ab48a84c410bc8d6f46527fb171799f8bfeb/fs.js#L233-L254

正如您所说,它正在使用“读取然后写入”方法。

关于nativescript - 你如何附加到 Nativescript 中的文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44710906/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com