在android中高效添加文本

发布于 2025-01-01 13:56:27 字数 348 浏览 4 评论 0原文

shell 中有一个非常好的功能,

例如,

# "asd" > myfile.txt

如果文件首先存在,则将“asd”放入 myfile.txt 中,然后将其删除,然后创建它,并将内容放入文件中。

但如果

# "asd" >> myfile.txt

如果该文件存在,则“asd”将被添加到文件末尾。

好吧,我需要一些有效的算法来做到这一点。

我有非常大的文本文件,我想做的就是在最后写一些东西,但它必须非常有效,我不想在愚蠢的事情上浪费资源,比如读取整个内容连接和写入...

There is one very nice feature in shell

for example

# "asd" > myfile.txt

puts "asd" in myfile.txt if the file exist first it is deleted then it is created and the content is put in the file.

but if

# "asd" >> myfile.txt

and if the file exist then the "asd" will be just added to the end of the file.

well I need some EFFICIENT algorithm that do exactly this.

I have very large text file and all I want to do is to write something to the end, but it must be very efficient I do not want to waste resources on stupid things like read the whole content concatenate and write...

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

暖伴 2025-01-08 13:56:27

我知道有关文件的一般概念。对您的情况有用的一件事是以附加模式打开文件。如果您以追加模式打开文件并尝试向其中写入数据,它只会追加(在文件末尾添加)给定的数据。

尝试在 android API 中搜索类似的功能。这是文件系统的一般特征。在linux中我们也熟悉这种类型的文件操作。

我希望它可以帮助你。

I know the general concepts about files. One thing which is useful for your case is opening a file in append mode. If you open a file in append mode and trying to write data to it, it just append(adds at the end of file) the given data.

Try to search for similar functionality in android API. This is general feature of File System. In linux also we have familiar with this type of file operations.

I hope it may help you.

梦忆晨望 2025-01-08 13:56:27

这个你在寻找什么。

Is this what you are looking for.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文