我在" / Android / data / Myfolder"中有一个music.mp3文件。我想编写代码来检查Myfolder.now中是否有music.mp3文件,我不知道如何编写代码。
答案 0 :(得分:1)
尝试使用File
类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
}