将各种数据类型的值写入文本文件以进行查询

时间:2022-06-05 22:34:55

What would be an ideal constructs / design for a program intended for querying lines of strings from a text file as a database? My main problem here is how do I make an object holding values of different data types (UUID, string, string, double, double, int) be written as a single package onto a text file of which these data will also be queried. I'm thinking of an array-like container for these values so that when queried, the output would print out the data in that package.

对于用于从文本文件中查询字符串行作为数据库的程序,理想的构造/设计是什么?我的主要问题是如何使一个对象保存不同数据类型的值(UUID,string,string,double,double,int)作为单个包写入文本文件,这些文件也将被查询。我正在考虑这些值的类似数组的容器,以便在查询时,输出将打印出该包中的数据。

2 个解决方案

#1


0  

Assuming that you do not need efficient querying, I think the best for you would be to use JSON format. Take a look at Gson library. It does nice JSON to object mapping and serialization.

假设您不需要有效的查询,我认为最适合您的是使用JSON格式。看看Gson图书馆。它对对象映射和序列化做了很好的JSON。

Here you can find a nice 2-minutes guide with example.

在这里,您可以找到一个很好的2分钟指南。

#2


0  

What is the reason for wanting to save to and query from a text file? Is it to avoid setting up a database daemon?

想要保存到文本文件并从中查询的原因是什么?是否要避免设置数据库守护程序?

You have a few options, depending on what you're trying to achieve and the reasons for doing so.

您有几个选择,具体取决于您要实现的目标以及这样做的原因。

  1. You could serialise your data constructs into text files which can then be unserialised directly into the original data types later.

    您可以将数据结构序列化为文本文件,然后可以将其直接反序列化为原始数据类型。

  2. You could also use a non-SQL solution, such as MongoDB, that would save your data to text files too.

    您还可以使用非SQL解决方案,例如MongoDB,它也可以将数据保存到文本文件中。

#1


0  

Assuming that you do not need efficient querying, I think the best for you would be to use JSON format. Take a look at Gson library. It does nice JSON to object mapping and serialization.

假设您不需要有效的查询,我认为最适合您的是使用JSON格式。看看Gson图书馆。它对对象映射和序列化做了很好的JSON。

Here you can find a nice 2-minutes guide with example.

在这里,您可以找到一个很好的2分钟指南。

#2


0  

What is the reason for wanting to save to and query from a text file? Is it to avoid setting up a database daemon?

想要保存到文本文件并从中查询的原因是什么?是否要避免设置数据库守护程序?

You have a few options, depending on what you're trying to achieve and the reasons for doing so.

您有几个选择,具体取决于您要实现的目标以及这样做的原因。

  1. You could serialise your data constructs into text files which can then be unserialised directly into the original data types later.

    您可以将数据结构序列化为文本文件,然后可以将其直接反序列化为原始数据类型。

  2. You could also use a non-SQL solution, such as MongoDB, that would save your data to text files too.

    您还可以使用非SQL解决方案,例如MongoDB,它也可以将数据保存到文本文件中。