在android中高效添加文本
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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我知道有关文件的一般概念。对您的情况有用的一件事是以附加模式打开文件。如果您以追加模式打开文件并尝试向其中写入数据,它只会追加(在文件末尾添加)给定的数据。
尝试在 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.
是这个你在寻找什么。
Is this what you are looking for.