title: How to replace files in same location using Download manager in Android?
body: <p>In my app I need to download some files(images,Pdf&amp;txt). I am successful to save files through download manager in Downloads folder, But I want if file already exist in downloads folder and user again click on same file then it delete older one in download folder and replace with new file. Please let me know how it is possible?</p>
  
  <p>My code:</p>
  
  <pre><code>  database = new DMS_Database(Files_Folders_Activity.this);
          if(!database.dididExist((doc_Id)))    // if file does not exist then it will save file in the database and in downloads folder.
          {
              database.Save_Doc(doc_Id, name, url);   //Database method
              System.out.println("you are here: Save Files");
              DownloadManager.Request request = new DownloadManager.Request(Uri.parse(url));
              request.setTitle(name);
              // in order for this if to run, you must use the android 3.2 to compile your app
              if (Build.VERSION.SDK_INT &gt;= Build.VERSION_CODES.HONEYCOMB) 
              {
                  request.allowScanningByMediaScanner();
                  request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
              }
              request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS + "/Downloads", name);
              DownloadManager manager = (DownloadManager) getSystemService(Context.DOWNLOAD_SERVICE);
              manager.enqueue(request);
          }
          else
          {
              database.update_Doc(Doc_Id,name,url);    
  //But if file already exist then How to delete file and again save on same location. I don't want duplicate file. Right now it is creating two websites also not updating database.
              System.out.println("you are here: update files");
              DownloadManager.Request request = new DownloadManager.Request(Uri.parse(url));
              request.setTitle(name); 
              // in order for this if to run, you must use the android 3.2 to compile your app
              if (Build.VERSION.SDK_INT &gt;= Build.VERSION_CODES.HONEYCOMB)
              {
                  request.allowScanningByMediaScanner();
                  request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
              }
                  request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS + "/Downloads", name);
                  DownloadManager manager = (DownloadManager) getSystemService(Context.DOWNLOAD_SERVICE);
                  manager.enqueue(request);
          }
                  database.close();
  </code></pre>
  
  <p>Please let mek now ow it is possible, thanks.</p>