Because the File.delete () method does not work

0

I have been frustrated for almost 2 days trying to find the failure because the registry.delete () method does not delete the file "Registry.txt". I'm working with Gui, and every time I click on a row of a JTable and then click on the "Ban" button, it does not delete the file "Registro.txt", and it does not write !!, however if I do it from another class, such as the class that has the main () method, if it clears. What I wanted to do, is to delete a line from the Registry.txt, writing in another txt all the lines that did not contain the String name, and then renaming it to the name Registry.txt I do not know what happens, I leave the extract

ActionListener ban = new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                int fila = table.getSelectedRow();
                String nombre = (String) modelo.getValueAt(fila, 0);
                modelo.removeRow(fila);
                try {
                    removeUser(nombre);

                } catch (IOException ex) {
                    System.out.println(ex.getMessage());
                }
            }
        };
        btnBanear.addActionListener(ban);


  public void removeUser(String nombre) throws IOException {
        String lee = null;
        String usuario = "";
        CharSequence aux = nombre;
        try {
            registro = new File("Registro.txt");
            tempFile = new File("Registro1.txt");
            lector = new BufferedReader(new FileReader(registro));
            fw = new FileWriter(tempFile);
            writer = new BufferedWriter(fw);

        } catch (FileNotFoundException ex) {
            System.out.println(ex.getMessage());
        } catch (IOException ex) {
            System.out.println(ex.getMessage());
        } catch (NullPointerException e) {
            System.out.println(e.getMessage());
        }

        while ((lee = lector.readLine()) != null) {
            System.out.println(aux);
            if (lee.contains(nombre)) {
                continue;
            } else {

                writer.write(lee);

            }
        }
        lector.close();
        fw.close();
        writer.close();
        registro.delete();
    
asked by Christian 14.08.2018 в 20:25
source

0 answers