Delete file (photo) from the folder when performing update

0

I'm having trouble with a code. I am creating a form with a profile photo, but when I make a change of the photo in the EDIT, I would like the photo to be deleted from the images folder. Today I can only delete and change the photo, but the old one remains. The code below is what I use to exclude a record from my list:

public void apagar(UsuarioModel selcionado){
   if (selecionado != null){
      try{
          if (new UsuarioDao().apagar(selecionado)){
              lista.remove(selcionado);
              }

      }catch(Exception e){
          System.out.println(e.getMessage());
      }
  }

}
    
asked by anonymous 23.05.2016 / 21:49

2 answers

0

If you have the path of the image or the file, just do it:

 File imagem = new File("path/da/imagem");
 imagem.delete();

.delete () = > Boolean return. Hope it helps.

    
24.05.2016 / 00:12
0

You need the file path first of all to take a look at the code below that will make it clear to you

String fileName = "C:\images\olamundo.jpg";
removerArquivo(fileName);
public void removeArquivo (String fileName) 
{
    File file = new File(fileName);
    file.delete();
}

I hope I have helped.

    
09.06.2016 / 16:55