简体   繁体   English

如何存储和检索用户特定的数据

[英]how to store and retrieve user-specific data

I am working on a first project, a FlashCard app. 我正在开发第一个项目,即FlashCard应用程序。

I would like to create a profile for every single user so that the user can make individual settings. 我想为每个用户创建一个profile ,以便用户可以进行单独的设置。

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 例如,我想为每个配置文件创建一个文件夹,其中serialized files are being stored了用户的serialized files are being stored

  1. What is an appropriate format to store this type of data? 什么是存储此类数据的适当格式?

Intuitively, I would opt for xml . 直观地讲,我会选择xml I have not worked with it yet, though. 不过,我还没有使用它。

  1. What is the general workflow when working with profiles and serialized data 使用配置文件和序列化数据时一般的workflow是什么

Here, I would check at program start whether any profiles exist at all . 在这里,我将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 . 加载配置文件后,我将deserialize与此特定profile associated所有数据。

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. 除非您想与其他程序共享配置文件数据,否则可以简单地使用Java默认序列化机制。 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 因此,您可以给它任何扩展名,例如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 通过使用ObjectInputStream https://docs.oracle.com/javase/8/docs/api/java/io/ObjectInputStream.htmlObjectOutputStream https://docs.oracle.com/javase/8/docs/api/java/ io / ObjectOutputStream.html,您可以轻松地序列化/反序列化配置文件数据或需要写入文件的任何其他数据

First you would define the directory structure where to store your profile data. 首先,您将定义用于存储个人资料数据的目录结构。 It could be in the same directory with application, say "profiles/". 它可能与应用程序位于同一目录中,例如“ 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. 程序启动时,它会检查“ profiles /”目录中是否有任何概要文件数据文件;如果是,它将列出文件概要文件供用户选择;如果不是,它将提示用户创建一个新的文件。

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

相关问题 身份验证后如何显示特定于用户的数据 - How can i display User-specific data after authentication 创建包含用户特定数据的WebSocket会话的最安全方法 - Safest way to create a WebSocket session containing user-specific data 如何在Play中实现用户特定的类型通用行为? - How to realize user-specific type-generic behaviour in Play? 应如何使用 spring 引导安全保护用户特定资源? - How should a user-specific resource be protected using spring boot security? 如何在android中使用SQlite存储和检索特定用户的数据 - How to store and retrieve data for a particular user using SQlite in android 如何在特定用户的改造下上传和检索数据? - How to upload and retrieve data under a specific user in retrofit? 从Firebase数据库中检索特定用户的数据 - Retrieve data of a specific user from a Firebase database 如何从 Firebase 实时数据库中检索具有 UID 的特定用户的特定数据 - How to retrieve specific data of a specific user with UID from a Firebase realtime database 如何仅为特定用户检索firebase数据库? - How to retrieve firebase database for specific user only? Android:如何在sharedpreferences中存储和检索Hashmap数据? - Android:how to store and retrieve Hashmap data in sharedpreferences?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM