You should override accept in the interface FilenameFilter and make sure that the parameter name
has only numeric chars. You can check this by using matches:
String[] list = dir.list(new FilenameFilter() {
@Override
public boolean accept(File dir, String name) {
return name.matches("[0-9]+");
}
});