Java:将对象写入文件以避免 java.lang.StackOverflowError
我想将大量数据写入文件。数据包含在一个对象中。对象被实现为可序列化。 问题是,当我尝试使用 ObjectOutputStream 的 writeObject 将其写入文件时,它会给出 StackOverflowError,因为对象的大小很大。
我只需要保存该对象,以便我可以再次打开并使用它,更改一些值,然后再次保存到磁盘。
目标文件是用 Neuroph 框架创建的 NeuralNetwork,所以我不喜欢研究它的大代码并一一挑选数据并将其序列化。
请有人建议一种方法来切片对象(或一些缓冲效果)并至少保存。我认为这样的事情就能解决问题。
谢谢。 :)
I want to write some large amount of data to a file. the data is contained in an object. object is implemented as serializable.
The thing is when I try to write it to a file using ObjectOutputStream's writeObject, it gives the StackOverflowError because the size of the object is large.
I only need to save the object so that i can open and use it again, change some values, and save to disk again.
The object file is a NeuralNetwork created with Neuroph framework, so i dont like to look into its big code and pick data one by one and serialize the stuff.
Please can someone suggest a way to slice the object ( or some buffering effect ) and save at least. i think that kind of thing would do the trick.
Thank you. :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您是否可以考虑增加堆栈大小(
-Xss2m
左右),因为也许只需在堆栈上添加更多内容就可以完成任务?除此之外,实际上没有一种方法可以分割对象图以进行序列化(在不了解对象的情况下)。
Can you consider increasing the stack size (
-Xss2m
or so) as maybe just having more on the stack will allow you to get it done?Beyond that there is not really a way to cut up an object graph for serialization (without understanding the objects).
这可能是 Neuroph 中的错误,因为图可能具有循环路径,导致无限递归。
在这种情况下,您需要自己进行(反)序列化。至少你会学到一些。由于 Neuroph 框架很精简,因此反射相对容易。
他们有像样的开发者论坛吗?
It might be an error in Neuroph, because graphs may have cyclic paths, leading to infinite recursion.
In that case you need to do the (de-)serialization yourself. At least you will learn some. With reflection that is relatively easy, as the Neuroph framework is lean.
Do they have a decent developer forum?