简体   繁体   English

如何将Java数组的数据存储在硬盘中,以便以后使用?

[英]How to store data of java array in Hard Disk, so as i can use it later?

Goodevening Sir/Mam, I am trying to make a small program that will be used for hotel room reservation, please tell me how to store the data of room's status on disk, as when we open the program next time we'll get the data. 晚上好,先生/女士,我正在尝试制作一个用于预订酒店房间的小程序,请告诉我如何在磁盘上存储房间状态数据,因为下次打开程序时,我们将获取数据。 Please help i am very new here. 请帮助我在这里很新。 Have a nice day! 祝你今天愉快!

序列化它可能是最好的。

One way to do this is serialize the array write it to a file. 一种方法是序列化数组,将其写入文件。 java-serialization has an example for serializing an object to a .txt file; java-serialization有一个将对象序列化为.txt文件的示例; you can adapt this code to serialize an array. 您可以修改此代码以序列化数组。

The usual way of doing this in Java is to serialize the data structure / class. 在Java中,执行此操作的通常方法是序列化数据结构/类。 It's normally pretty easy to do as you just extend Serializable in the appropriate class. 通常,您只需在适当的类中扩展Serializable就可以很容易地做到这一点。

Before you leap into implementing a hotel reservation system based on writing stuff into files, you need to consider using a relational database instead. 在开始实施基于将内容写入文件的酒店预订系统之前,您需要考虑使用关系数据库。 A decent RDB will give better performance AND you won't have to worry about your program crashing with unsaved updates ... or (worse still) in the middle of writing the updates to disk. 体面的RDB将提供更好的性能,并且您不必担心程序会因未保存的更新而崩溃……或者(甚至更糟)在将更新写入磁盘的过程中。

The fact you are asking this question suggests (to me) that you are short on knowledge and experience. 您在问这个问题的事实表明(对我而言)您缺乏知识和经验。 If this is a real project for a real hotel, stop now before someone gets hurt! 如果这是真正酒店的真正项目,请在受伤之前立即停止! (But if this is a student project, feel free to continue, and learn. But I still think a proper database is the right way to go ...) (但是,如果这是一个学生项目,请继续学习。但是我仍然认为正确的数据库是正确的方法……)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用I / O表达式(Java)将数据从阵列存储到硬盘中 - Storing data from an array into the hard disk with I/O expressions (Java) 如何将对象类型的数组存储为字符串,以便另一个类以后可以调用并打印该字符串。 爪哇 - How to store an array of object types as a string so another class can later call and print that string. java 我想知道如何在Matlab中存储一些数据,以后可以从Java代码中调用这些数据吗? - I want to know how to store some data in Matlab which I can later call from Java code? 如何存储类的类型以供以后在Java中使用? - How do I store the type of a class for use later in Java? 如何将值存储在2D数组中以备后用? - How do I store the values in a 2D array for later use? 如何将数组添加到此循环中,以便存储数据 - How can I add an array an array to this loop so I can store the data Java脚本无法自动写入硬盘,但是Java可以这样做 - java script can not automatically write to hard disk But Java can do so 如何在Linux,Windows和Mac上使用Java + JNI检索硬盘的唯一ID - How can I retrieve a hard disk's unique ID using Java+JNI on Linux, Windows and Mac 如何通过Java收集有关硬盘的数据? - How to collect data about hard disk via Java? 如何将CSV中的数据存储到Java中的数组中? - How can I store data in CSV into an array in Java?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM