File Filtering
How to retrieve file with particular extension
package com.example.gridviewexample;
import java.io.File;
import java.io.FilenameFilter;
public class MyFileFilter implements FilenameFilter{
@Override
public boolean accept(File dir, String filename) {
return (filename.endsWith(".jpeg") || filename.endsWith(".jpg") || filename.endsWith(".png")) ;
}
}
How to Apply File Filter
strImagFileList = new ArrayList<String>();
for (int i = 0; i < alFile.size(); i++) {
File f = new File(alFile.get(i));
if (new MyFileFilter().accept(f, f.getName())) {
strImagFileList.add(f.getAbsolutePath());
}
}
for (int i = 0; i < alFile.size(); i++) {
File f = new File(alFile.get(i));
if (new MyFileFilter().accept(f, f.getName())) {
strImagFileList.add(f.getAbsolutePath());
}
}
No comments:
Post a Comment
Must Comment