(android)如何编写代码来检查文件夹中的文件

(android)How to write code to check a file in a folder

我在“/Android/data/Myfolder”中有一个 music.mp3 文件,我想编写代码来检查 Myfolder.Now 中是否有 music.mp3 文件,我不知道如何编写代码。

尝试使用 File class exists() 这样的方法 :-

  String folderPath = "/Android/data/Myfolder";
        String fileName = "music.mp3";
        File music = new File(folderPath+"/"+fileName);
        if(music.exists()){ // return true if found
            System.out.println(fileName +"found");
            // other found logics here
        }

        else {
            System.out.println(fileName +" not found here");
            // other not found logics here
        }