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'代碼。尤其要看你的程序是否在啓動之前立即寫入文件,然後再讀取它。 –
我認爲是的,這是我的代碼。 –