仅删除从文件夹中的.jpg文件的android [英] Delete only .jpg files from folder in android
本文介绍了仅删除从文件夹中的.jpg文件的android的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是没有办法从文件夹中删除仅.jpg文件? 这是我的删除方法:
如果(dir.isDirectory()){
的String []孩子= dir.list();
的for(int i = 0; I< children.length;我++){
新的文件(目录,孩子们[I])删除();
}
}
如何从文件夹中删除仅.jpg文件?
解决方案
如果(dir.isDirectory()){
的String []孩子= dir.list();
的for(int i = 0; I< children.length;我++){
字符串文件名=儿童[I]
如果(filename.endsWith(JPEG)|| filename.endsWith(JPG))
新的文件(目录,文件名).delete();
}
}
或你preFER的换每个版本
如果(dir.isDirectory()){
的String []孩子= dir.list();
对(串儿:儿童){
如果(child.endsWith(JPEG)|| child.endsWith(JPEG))
新的文件(目录,子女).delete();
}
}
This is any way to delete only .jpg files from folder? This is my remove method:
if (dir.isDirectory()) {
String[] children = dir.list();
for (int i = 0; i < children.length; i++) {
new File(dir, children[i]).delete();
}
}
How can I remove only .jpg files from folder?
解决方案
if (dir.isDirectory()) {
String[] children = dir.list();
for (int i = 0; i < children.length; i++) {
String filename = children[i];
if (filename.endsWith(".jpeg") || filename.endsWith(".jpg"))
new File(dir, filename).delete();
}
}
or you prefer the for-each version
if (dir.isDirectory()) {
String[] children = dir.list();
for (String child : children) {
if (child.endsWith(".jpeg") || child.endsWith(".jpeg"))
new File(dir, child).delete();
}
}
这篇关于仅删除从文件夹中的.jpg文件的android的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文