-2

How to delete an Object from a file ??

           DefaultListModel model = (DefaultListModel) list.getModel();
            int selectedIndex = list.getSelectedIndex();
            if (selectedIndex != -1) {

                model.removeElement(list.getSelectedValue());
               }

with this code I am able to delete only from the list. Is there a code to remove object from the list and file ?

user7
  • 11
  • 1
  • 5
  • Simplest approach is: Load list from file, remove whatever elements you want from the list, overwrite file with modified list. – m0skit0 Jan 12 '15 at 11:14
  • Please specify what you want by adding information about where & how your data is stored, how you load it into the model and what exactly you are planning to do. – maxdev Jan 12 '15 at 11:14

1 Answers1

0

You have correctly read the content of the file.

You have correctly removed the element from the list.

The task remaining is to open your file for writing and save the new state of the list.

Lajos Arpad
  • 64,414
  • 37
  • 100
  • 175