English 中文(简体)
编外文件的书面数据
原标题:writing data in to files with java

我在java书写了一台服务器,使客户能够进行类似于20个问题的游戏。 游戏本身基本上是一个双向树,其子点是关于物体的问题,在物体特征上留下的树。 当游戏gue错时,它需要能够从参与者那里获得正确答案,并将其添加到树上。 然后将这些数据保存到随机查阅档案中。

The question is: How do you go about representing a tree within a file so that the data can be reaccessed as a tree at a later time.

如果你知道,在撰写/阅读档案时,我能找到有关保存像树木这样的数据结构的信息,那么请将其联系起来。 非常感谢。


感谢大家的迅速答复。 这是一个学校项目,因此,它有一些奇数的要求,如使用随机查阅档案和电话网。

问题回答

This data is then saved to a random access file.

这是解决你问题的艰难途径(我指的是“很少接触”。

The problem you are really trying to solve is how to persist a "complicated" data structure. In fact, there are a number of ways that this can be done. Here are some of them ...

  • 使用 Java的持久性。 这是简单易行的;确保你的数据结构具有序列性,然后,只有几条编码线用于序列化,只有几条条线可以脱射。 底部是:

    • Serialized objects can be fragile in the face of code changes.
    • Serialization is not incremental. You write/read the whole graph each time.
    • If you have multiple separate serialized graphs, you need some scheme to name and manage them.
  • 使用XML。 这一工作比 Java的坚持要多,但它的好处是不那么脆弱。 如果情况不正确,那么你就有机会将其与异常低价竞标或文本编辑。 (有XML“具有约束力的”图书馆,消除了许多冰川编码。)

  • 利用一个数据库。 这涉及 Java持续存在的方方面面,但涉及更多的编码......并使用不同的计算模式获取持久性数据(频率和图表导航)。

  • 利用一个数据库和一个目标相关的制图技术;例如,JPA或JDO的实施。 (自由是民众的选择)。 数据库和内层对数据的看法之间的这些桥梁以更透明或更不透明的方式,避免了你需要在KQ数据库和XML案件中写的许多冰川法。

我认为你重新寻找序列化。 为此:

As mentioned, serialization is what you are looking for. It allows you to write an object to a file, and read it back later with minimal effort. The file will automatically be read back in as your object type. This makes things much easier than trying to store the object yourself using XML.





相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签