更新在java中写入文本文件的对象 [英] Update objects written to a text files in java

查看:136
本文介绍了更新在java中写入文本文件的对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

将Java对象或List写入文本文件即可。但我想知道如何更新或重写之前编写的对象,而无需再次编写对象。例如,假设有一个java.util.List有一组Objects。然后该列表被写入文本文件。然后,将再次读取该文件并从列表中获取所有对象,然后在运行时通过Java应用程序更改一个对象的值。然后我不需要将整个列表写回文本文件。相反,只需要在文本文件中重写或更新列表中的更新对象,而无需再次重写整个列表。请提供任何建议或有用的示例代码来源。

Writing Java objects or a List into a text file is ok. But I want to know how I can update or rewrite a object which was written previously without writing objects again. For example, let s assume there is a java.util.List has a set of Objects. and then that list is written to a text file. Then later that file will be read again and get all objects from list and then change one object's value at run time by a java application. Then I don't need to write entire list back to the text file. Instead only the updated object in the list is required to be rewritten or updated in the text file without rewriting the whole list again. Any suggestion, or helpful source with sample codes please.

推荐答案

看看 RandomAccessFile 。这将允许您搜索所需文件中的位置,并仅更新要更新的部分。

Take a look at RandomAccessFile. This will let you seek to the place in the file you want, and only update the part that you want to update.

还要看一下问题

这篇关于更新在java中写入文本文件的对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆