title: delete image from the folder
body: <p>I want to delete one image from the folder when I delete a user from the table with this image. Here is my code:
  //first I can the function that finds a path of the image in the folder</p>
  
  <pre><code>public void deleteStudent(String name) {
      try {
          CallableStatement statement = null;
          Connection data = getmyConnection(); 
          statement = data.prepareCall("{call delete_student(?)}");
  
          statement.setString(1, name);
          //statement.registerOutParameter(2, java.sql.Types.VARCHAR);
          statement.executeQuery();           
      } catch (Exception c) {
          c.printStackTrace();
      } 
  
      //After I call the function to delete image from directory       
      deleteImageDerictory(name);          
  }
  </code></pre>
  
  <p>This method allows choosing the image from the directory when I get the image I add the path in jTextField1.getText(). </p>
  
  <p>//use this method to get the path of my image.</p>
  
  <pre><code>private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {                                         
         JFileChooser file = new JFileChooser();
                  file.setCurrentDirectory(new File(System.getProperty("user.home")));
  
                  FileNameExtensionFilter filter = new FileNameExtensionFilter("*.Images", "jpeg", "jpg", "png");
  
  
  
  
  file.addChoosableFileFilter(filter);
                  int result = file.showSaveDialog(null);
                  if(result ==JFileChooser.APPROVE_OPTION) {
                      File selectedFile = file.getSelectedFile();
                      //GET ABSOLUTE PATH OF PICTURES
                      jTextField1.setText(selectedFile.getAbsolutePath());
                      //addPicture.setText(selectedFile.getName()); 
                      //GET NAME OF PICTURES
                      //getPicName = selectedFile.getName();
  
  
  
  
  } else if(result == JFileChooser.CANCEL_OPTION) {
                      System.out.println("File not found!");
  
                  }
      } 
  </code></pre>
  
  <p>//I use this method to call another method deleteImageDerictory(jTextField1.getText());</p>
  
  <pre><code>private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                         
          try{
     deleteImageDerictory(jTextField1.getText());
            }catch(Exception e) {
      e.printStackTrace();
  }
      } 
  
  
  public void deleteImageDerictory(String name) {
      String pictureName =  null; 
      try {
          CallableStatement statement = null;
          Connection data = getmyConnection(); 
          statement = data.prepareCall("{call get_picture(?)}");
          statement.setString(1, name);
          //statement.registerOutParameter(2, java.sql.Types.VARCHAR);
          myResults = statement.executeQuery();
  
          while (myResults.next()) {
              //COPY PATH IN pictureName 
              pictureName = myResults.getString(1);
          }
  
          myResults.close();
      } catch (Exception c) {
          c.printStackTrace();
      }
  
      //DELETE ELEMENT FROM FOLDER 
      File sourceFile = new File(pictureName);
      File file = new File("/Computer/NetBeans IDE 8.2/NewDataBase/src/newdatabase/images/");
  
       images = file.listFiles();
  
       File file2 = new File(file.getAbsolutePath(), sourceFile.getName() );
  
      boolean deleted = file2.delete();
      System.out.println(deleted);
  }
  </code></pre>
  
  <p>I just don't know how to delete image from folder when I find it. Any ideas?</p>