简体   繁体   中英

how to store and retrieve user-specific data

I am working on a first project, a FlashCard app.

I would like to create a profile for every single user so that the user can make individual settings.

Besides that, I would like to organize the users's data around that profile. For example, I want to create a folder for every profile in which the users' serialized files are being stored

  1. What is an appropriate format to store this type of data?

Intuitively, I would opt for xml . I have not worked with it yet, though.

  1. What is the general workflow when working with profiles and serialized data

Here, I would check at program start whether any profiles exist at all .

If that's the case the user should be able to either add or load a profile. Otherwise the user should be prompted to create a profile.

Once, a profile has been loaded, I would deserialize all the data that is associated with this particular profile .

Does that make sense?

Cheers, Adnrew

  1. Unless you want to share the profile data with other programs, you can simply use Java default serialization mechanism. Add other fields to the data structure as necessary

public class Profile implements java.io.Serializable { private String name; public String getName() { return name; } public void setName(String name) { this.name = name; } }

The file will be stored in binary format. So you can give it any extension you want, eg profile1.dat

  1. By using ObjectInputStream https://docs.oracle.com/javase/8/docs/api/java/io/ObjectInputStream.html and ObjectOutputStream https://docs.oracle.com/javase/8/docs/api/java/io/ObjectOutputStream.html you can easily serialize / deserialize your profile data or any other data you need to write into files

First you would define the directory structure where to store your profile data. It could be in the same directory with application, say "profiles/". When the program starts it checks if there are any profile data files in the "profiles/" directory, if yes it will list them for the user to choose, if not it will prompt the user to create a new one.

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