class JPGFileFilter implements FileFilter {
@Override
public boolean accept(File pathname) {
if (pathname.getName().endsWith(".jpg")) {
return true;
}
return false;
}
public static File[] countImage() throws UnsupportedEncodingException {
String path = ChooseForm.class.getProtectionDomain().getCodeSource().getLocation().getPath();
String decoded = URLDecoder.decode(path, "UTF-8");
File fileOuttemp = new File(decoded);
File cwd = fileOuttemp.getParentFile();
File[] jpgFiles = cwd.listFiles(new JPGFileFilter());
if (jpgFiles.length > 0) {
return jpgFiles;
}
return null;
}
}
Metoda countImage() ma za zadanie zwracać tablice ze znalezionymi plikami. Działa ok, ale czy kod jest poprawny szczególnie ta linia: File[] jpgFiles = cwd.listFiles(new JPGFileFilter()); wywołanie konstruktora klasy w tej samej klasie klasie?