How to delete SQLite database in download files?

Issue

This Content is from Stack Overflow. Question asked by star.java

My android project apk files in Download directory. I want to deleted apk and sqlite database files. Sqlite database file creating by android program. Apk files deleted but sqlite database file didn’t delete.

public void deleteApks(){
    String dbpath = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS).getPath();
    //File dbpath = new File(getExternalFilesDir(Environment.DIRECTORY_DOWNLOADS).getPath());
    File fileList = new File(String.valueOf(dbpath));
    if (fileList != null){
        System.out.println("list" + fileList.listFiles().toString());
        File[] filenames = fileList.listFiles();
        System.out.println("length" + filenames.length);

        for (File tmpf : filenames){
            if(tmpf.getName().contains("apkName") || tmpf.getName().contains("databaseName"))
                tmpf.delete();

        }
    }
}



Solution

This question is not yet answered, be the first one who answer using the comment. Later the confirmed answer will be published as the solution.

This Question and Answer are collected from stackoverflow and tested by JTuto community, is licensed under the terms of CC BY-SA 2.5. - CC BY-SA 3.0. - CC BY-SA 4.0.

people found this article helpful. What about you?