title: Delete Image from Local path using Spring MVC
body: <p>Here is the Method using for saving Image to my local system using Spring MVC</p>
  
  <pre><code>private void saveProductImage(Product product)
      {
          System.out.println("Product Image - "+ product.getProduct_image());
              try{
                  if(product.getProduct_image()!= null)
                  {
                      Path path=Paths.get("E://Eclipse//WorkSpace//TechGrab//src//main//webapp//resources//images//product-images//"+ product.getProduct_id()+".png");
                      product.getProduct_image().transferTo(new File(path.toString()));
                      System.out.println("Product Image Saved !!!");
                  }
              }
              catch(Exception e)
              {
                  System.out.println("Failed to Save image !!");
              }
      }
  </code></pre>
  
  <p>here The <strong>Product</strong> is the My Model, and  <em>path</em> is the object of <strong>Path</strong> where im saving the image as the product ID od the image using </p>
  
  <pre><code>product.getProduct_image().transferTo(new File(path.toString()));
  </code></pre>
  
  <p>Now - i would Like to delete the Product details along with the Product Image, so here is my Product Details getting deleted with this </p>
  
  <pre><code>@Transactional
      public void deleteProduct(String product_id) {
          Session ses = sf.openSession();
          Transaction tr = ses.beginTransaction();
          Product temp = ses.get(Product.class, product_id);
          ses.delete(temp);
          tr.commit();
          ses.close();
  
      }
  </code></pre>
  
  <p>which is getting the delete method for the product Id but now still the image is been saved in the local system with the product id , how can i delete the Product Image ! Help me out ty :)</p>
  
  <p>I have tried this - but its not working !</p>
  
  <pre><code>private void deleteProductImage(Product product)
      {
          System.out.println("Product Image - "+ product.getProduct_image());
              try{
                  if(product.getProduct_image()!= null)
                  {
                      Path path=Paths.get("E://Eclipse//WorkSpace//TechGrab//src//main//webapp//resources//images//product-images//"+ product.getProduct_id()+".png");
                      Files.delete(path);
                      System.out.println("Product Image Deleted !!!");
                  }
              }
              catch(Exception e)
              {
                  System.out.println("Failed to Delete image !!");
              }
      }
  </code></pre>
  
  <p>sorry for bad English </p>