I have a .csv file that contains information, but when I remove information (in this case contacts) from the console output the .csv file is not being updated. How to solve?
private void insertContact(String contactName) {
contactsListModel.addElement(new Contact(contactName));
}
private void setContactsList() {
contactsListModel = new DefaultListModel<Contact>();
contactsList = new JList<Contact>(contactsListModel);
contactsList.setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION);
contactsList.setLayoutOrientation(JList.VERTICAL);
contactsList.setVisibleRowCount(-1);
contactsList.setBackground(Color.LIGHT_GRAY);
loadContacts();
add(contactsList, BorderLayout.CENTER);
}
private void setContactsLabel() {
contactsLabel = new JLabel("Contacts:");
contactsLabel.setOpaque(true);
contactsLabel.setBackground(Color.WHITE);
add(contactsLabel, BorderLayout.NORTH);
}
public void loadContacts(){
BufferedReader br = null;
String line = "";
String separator = ";";
try {
br = new BufferedReader(new FileReader("diretorio"));
while ((line = br.readLine()) != null) {
String[] contactName = line.split(separator);
contactsListModel.addElement(new Contact(contactName[0]));
System.out.println( );
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
if (br != null) {
try {
br.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
}