在java中保存为文本文件或对象有什么区别以及何时使用?
我需要保存一个图表以便加载它并对其应用算法...... 那么最好将图形保存为文本文件或对象吗? ... 或者还有其他有效的方法吗???
I need to save a graph in order to load it and apply algorithms on it ...
so what is best to do save the graph as text file or as an object ?? ...
or is there another efficient way ???
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您可以使节点和边缘类可序列化,那将是最简单的事情。您不必担心在写入时处理循环引用或在读取时重建它们;它们将自动重组。
如果您使用符号数据,则每个节点都需要有一个唯一的 ID,除非您保证图中没有两个节点具有相同的数据。然后,在重建图形时,您需要维护重建节点的符号表。很多簿记令人头疼。
If you can make your node and edge classes serializable, that will be the easiest thing. You won't have to worry about dealing with circular references on write or reconstructing them on read; they will automatically be reconstituted.
If you use symbolic data, then you will need to have a unique id for each node unless you are guaranteed that no two nodes in the graph will ever have the same data. Then you'll need to maintain a symbol table for reconstructed nodes when you reconstruct the graph. Lots of bookkeeping headaches.