Add data from Jlist to file
Hi all,
I am currently developing a java application that has a combo box and
when the user presses a button to delete an item out of the JList I
would like the data that is left inside the combo box to be written to
a CSV file so all the computer names go down in a column and not in a
row which is what it is doing currently. Below is the code I am using
in order to do this:
int index = lstComputerExceptions.getSelectedIndex();
model.remove(index);
int size = model.getSize();
if (size == 0) { //Nobody's left, disable firing.
btnDelete.setEnabled(false);
} else { //Select an index.
if (index == model.getSize()) {
//removed item in last position
index--;
}
lstComputerExceptions.setSelectedIndex(index);
lstComputerExceptions.ensureIndexIsVisible(index);
String computerName = model.toString();
StringTokenizer st = new StringTokenizer(computerName,
"[,");
st.nextToken();
String computer = st.nextToken();
try {
BufferedWriter out = new BufferedWriter(new
FileWriter("C:\\Documents and Settings\\All Users\\Application Data\
\Remote Shutdown\\ExceptionsListTemp.csv"));
out.write(computer);
out.close();
// initiateComputerList();
} catch (IOException ex) {
System.err.println("Failed to add information to file");
statusBar.setForeground(Color.red);
statusBar.setText("Failed to add " +
txtComputerName.getText());
}
}
Any help in this matter would be highly appreciated.
Thank you