0
public void openFile(){
try {
l = new Formatter("try.txt");
System.out.println("Opened File");
} catch (Exception e){
System.out.println("Did not open file");
}
}
public void addRecord(){
l.format("%s", nameField.getText());
System.out.println("Added Name" + " " + nameField.getText());
}
public void onClose(){
l.close();
}
/*
So I am trying to store user data, I have a gui and anytime they click sign up i want to store the namefield in an array list, is it possible that anytime I close and reopen the program and someone else puts in their name it just adds to the array list instead of overriding what the earlier person put in?
Example is in my gui i type in mike as name, I close it and reopen it and put in john as the name, would that add mike and john or would it be just john? and how do I make them co-exist?
Thank you
它将其读取到文件中,但每次关闭该程序并再次运行它时,它将替换第一行中的任何内容。urenraintity arrayList存储
我知道如何使用文本文件来做到这一点,但每当它进入文本文件并关闭并打开文本文件时,文本文件也会发生变化。我被卡住了...... –
听起来好像你的问题是在首先从文本文件读取/写入的代码中。看看那里,而不是'ArrayList'代码。尤其要看你的程序是否在启动之前立即写入文件,然后再读取它。 –
我认为是的,这是我的代码。 –