我正在创建一个登录和注册表单只是为了练习。当应用程序第一次运行时,我希望首先显示注册表单。如何检测应用程序是否是第一次运行?
最佳答案
您可以做的一件事是检查文件是否存在。如果它存在,那么您知道该应用程序以前已经运行过,否则您知道它以前没有运行过,因此您创建它。
File file = new File("some/path/filename.txt");
boolean firstRun = false;
if(!file.exists()){
firstRun = true;
file.createNewFile();
}
if(firstRun){
// Code to run if it is the first time running the app
}else{
// Code to run if it is not the first time running the app
}
将来,该文件可能会用于用户配置等。
关于java - 检测 Java 应用程序中的首次用户,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31763431/