How can i make download manager overwrite an exisiting file instead of renaming the file in android

前端 未结 1 520
春和景丽
春和景丽 2020-12-09 18:52

I have a database file which is on the sdcard and now when a new database file is downloaded i need it to overwrite the old one instead of renaming it here is my downloading

相关标签:
1条回答
  • 2020-12-09 19:10

    when you're submitting the file to the download manager check if the file already exists. then delete it.

    private boolean isFileExists(String filename){
    
        File folder1 = new File(Environment.getExternalStorageDirectory().getAbsolutePath() + filename);
        return folder1.exists();
    
    
    }
    
    private boolean deleteFile( String filename){
    
        File folder1 = new File(Environment.getExternalStorageDirectory().getAbsolutePath() + filename);
        return folder1.delete();
    
    
    }
    
    0 讨论(0)
提交回复
热议问题