用于zip文件的Java检查目录

use*_*732 3 java directory zip android if-statement

我有以下代码检查sdcard上是否存在文件夹,我想添加另一个if语句,如果文件夹存在,检查实际文件夹中是否存在zip文件,如果它实际存在的话.我该怎么做才能检查zip扩展名的文件夹.该文件夹应该有很多拉链但我只想检查以确保有拉链和其他文件扩展名.我感谢你对此提供的任何帮助.

File z = new File("/mnt/sdcard/folder");
if(!z.exists()) {
Toast.makeText(MainMethod.this, "/sdcard/folder Not Found!", Toast.LENGTH_LONG).show(); 
} else {
Toast.makeText(MainMethod.this, "/sdcard/folder Found!", Toast.LENGTH_LONG).show();
}
Run Code Online (Sandbox Code Playgroud)

编辑: 谢谢你的帮助,这是我最终使用你的帮助,我还没有测试它,但它看起来不错.

    File z = new File("/mnt/sdcard/Folder");
    if(!z.exists()) {
           //create folder
} else {
        FilenameFilter f2 = new FilenameFilter() {
        public boolean accept(File dir, String filename) {
        return filename.endsWith("zip");
        }
        };
            if (z.list(f2).length > 0) {
            // there's a zip file in there..
            } else {
            //no zips inside folder
        }
    }
Run Code Online (Sandbox Code Playgroud)

Ben*_*ton 6

File f = new File("folder");
FilenameFilter f2 = new FilenameFilter() {
public boolean accept(File dir, String filename) {
return filename.endsWith("zip");
}
};
if (f.list(f2).length > 0) {
// there's a zip file in there..
}
Run Code Online (Sandbox Code Playgroud)

试试以上..