[英]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
Intuitively, I would opt for xml
. 直观地讲,我会选择
xml
。 I have not worked with it yet, though. 不过,我还没有使用它。
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 干杯,阿德鲁
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
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.html和ObjectOutputStream
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.