在java中存储数据的方法 [英] Methods for storing data in java

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

问题描述

在我的软件中,我想存储一些数据,以后他们将被使用。类似于数据库来存储数据:

In my software I want to store some data, that later they will be used. Something like a database to hold data:

Date, source path, destination path, and an array of file names.

还有另一个表来保存有关ftp连接的信息:

Also another table to hold information about ftp connection:

Host, port, username and password

需要知道什么方法可用于存储和解析这些数据。我注意到有一个文件类型称为.csv,这是我的选择吗?

I need to know what methods are available to store and parse these data. I noticed there is a file type called .csv, is this an option for me? And is there any other option?

推荐答案

我认为这取决于你想要存储多少数据和你需要什么

I think this depends a lot on how much data you want to store and how you need to access it.

如果您的应用程序将收集大量结构化数据,例如用户个人资料或产品信息,即如果您的应用程序是关于一个数据库,然后,是的,因为其他人已评论某种SQL数据库会有意义。

If your application is going to be collecting a lot of structured data, such as user profiles, or product information, ie, if your application is all about a database then, yes as others have commented some sort of SQL database would make sense.

如果你的需要更多的只是存储一些会话信息,也许像GUI窗体的最后一个状态,你可能想只是序列化数据并将其写入一个简单的文本文件。

If your needs are more along the lines of just storing some "session" information, maybe like the last state of a GUI form for example, you might want to just serialize the data and write it to a simple text file.

一个简单的方法是将数据序列化为人类可读的格式,如JSON,然后写入文本到文件,然后读回它,并在需要从存储中恢复时将其反序列化。

One simple way to do that would be to serialize the data in a human readable format such as JSON and then write the text to a file, and then read it back and deserialize it when you need to restore it from storage.

如果这是您要查找的内容,请查看< a href =https://sites.google.com/site/gson/gson-user-guide =nofollow> gson (来自google),它提供了一个非常容易的转换java对象到JSON,然后又返回。

If this is what you are looking for take a look at gson (from google), it provides a very easy what to convert a java object to JSON and back again.

JSON,只是文本,所以你可以读写它到一个简单的文本文件。

JSON, is just text, so you can just read and write it to a simple text file.

这篇关于在java中存储数据的方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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