简体   繁体   中英

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; you can adapt this code to serialize an array.

The usual way of doing this in Java is to serialize the data structure / class. It's normally pretty easy to do as you just extend Serializable in the appropriate class.

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.

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 ...)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM