Java Messenger:在计算机上保存消息档案
我正在做一个 Java Messenger 供人们聊天,我正在寻找一种在用户计算机上记录消息档案的方法。
我心中有两种可能性:
将对话保存在我存储在文档文件夹中的 XML 文件中。
要使用SQlite,但问题是我不知道如何将它集成到我的安装包中,也不知道它是否非常有用。
对您来说最好的解决方案是什么?
谢谢
I am doing a Java Messenger for people to chat and I an looking for a way to record the message archives on the user's computer.
I have 2 possibilities in my mind :
To Save the conversations in XML files that I store in my documents folder.
To use SQlite, but the problem is that I don't know how it is possible to integrate it to my setup package and I don't know if it is very useful.
What would be the best solution for you ?
Thank you
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
另一种选择是使用 JavaDb,它随 Java 6 免费提供(以及更高版本)
在做出选择之前,您应该考虑以下问题:
等等。即使是一个简单的文本文件也很可能就足够了。也许您最好的选择是选择一个简单的解决方案(例如文本文件)并实现它,然后看看您能走多远。但是,请提供合适的持久性级别抽象,以便您将来可以以最小的干扰插入不同的解决方案。
Another option is using JavaDb, which comes for free with Java 6 (and later versions)
Before you make a choice, you should think about questions such as:
etc. It's quite possible that even a simple text file would suffice. Perhaps your best bet is to choose a simple solution (e.g. a text file) and implement that, and see how far it takes you. However, provide a suitable persistence level abstraction such that you can slot in a different solution in the future with minimal disruption.
我会选择 XML 文件,因为它们更通用,并且可以在您的 Messenger 之外以或多或少的人类可读格式打开。我使用 Pidgin 进行即时消息传递,它以 XML 格式保存聊天历史记录。另外,要从应用程序中读取历史记录,您可以轻松地以 HTML 格式进行转换,以便更好地显示它。
I would go for the XML files as they are more generic and could be opened outside your messenger with more or less human readable format. I use Pidgin for instant messaging and it saves chat history in XML. Also to read the history from your application you can transform then easily in HTML to display it nicely.
如果您使用 JAXB,则将 Java 对象与 XML 相互转换非常容易。您只需在类上添加一些注释,然后通过 JAXB 编组器/反编组器运行它们。请参阅 http://docs.oracle.com/javaee/5/tutorial/ doc/bnbay.html
If you use JAXB, converting Java objects to/from XML is very easy. You just put a few annotations on your classes, and run them through a JAXB marshaller/unmarshaller. See http://docs.oracle.com/javaee/5/tutorial/doc/bnbay.html
使用google的protocolbuffer或者10gen的bson。它们更小、更快。
http://code.google.com/apis/protocolbuffers/docs/javatutorial.html
http://bsonspec.org/
一个问题是这些位于二进制演示文稿中,您可能想要使存档透明/可读用户
Use google's protocolbuffer or 10gen's bson. they are much smaller and faster.
http://code.google.com/apis/protocolbuffers/docs/javatutorial.html
http://bsonspec.org/
One issue is these are in the binary presentation and you might want to make the archive transparent/readable to users