对于ZIP文件中的Java检查目录 [英] Java check directory for zip files
问题描述
我有低于code进行检查,查看是否在SD卡中存在的文件夹,我想如果语句添加另一种,如果该文件夹存在,以检查是否有实际的文件夹中的zip文件,如果事实上存在,它。我能做什么检查该文件夹的压缩扩展。该文件夹应该有很多它的拉链,但我只希望它检查,以确保有拉链,没有其他文件扩展名。我感谢你任何帮助。
文件Z =新的文件(到/ mnt / SD卡/文件夹);
如果(!z.exists()){
Toast.makeText(MainMethod.this,/ SD卡/文件夹不存在!,Toast.LENGTH_LONG).show();
}其他{
Toast.makeText(MainMethod.this,/ SD卡/文件夹中找到!,Toast.LENGTH_LONG).show();
}
编辑:
谢谢你们在这里帮助是我结束了在你的帮助使用,我没有测试它没有,但它看起来不错。
文件Z =新的文件(到/ mnt / SD卡/文件夹);
如果(!z.exists()){
//创建文件夹
}其他{
FilenameFilter的F2 =新的FilenameFilter(){
公共布尔接受(文件目录,字符串文件名){
返回filename.endsWith(ZIP);
}
};
如果(z.list(F2)。长度大于0){
//那里面有一个zip文件..
}其他{
//文件夹内无拉链
}
}
文件f =新的文件(文件夹);
FilenameFilter的F2 =新的FilenameFilter(){
公共布尔接受(文件目录,字符串文件名){
返回filename.endsWith(ZIP);
}
};
如果(f.list(F2)。长度大于0){
//那里面有一个zip文件..
}
试试上面的..
I have the below code which checks to see if folder exists on the sdcard, I would like to add another if statement if the folder exists to check that there are zip files inside the actual folder if it in fact exists. What could i do to check the folder for a zip extension. The folder should have a lot of zips in it but i only want it to check to make sure there are zips and no other file extension. I thank you for any help with this.
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();
}
EDIT: Thanks guys for the help here is what i ended up using with your help, i haven't tested it yet but it looks good to me.
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
}
}
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..
}
Try the above..
这篇关于对于ZIP文件中的Java检查目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!