+ 7

the variable filename2 is only assigned to the last file in the directory.I want to loop through each file in the directory.

// get Names of image files in the knowledge base': String absolutePath = "C:/Write"; File dir = new File(absolutePath); File[] filesInDir = dir.listFiles(); for(File file:filesInDir) { ImageIO.read(file); filename2 = file.getPath(); } int ret; ret = compareFeature(filename1, filename2); if (ret > 0) { System.out.println(" Image Match found."); } else { ImageIO.write((RenderedImage) image, "jpg", new File("C:/Write/"+ filename)); System.out.println(" Image Match not found."); }

29th Apr 2019, 7:51 PM
Baba Yunus Abdul Yekin
Baba Yunus Abdul Yekin - avatar
1 Answer
+ 5
for(File file: filesInDir){ filename2 = file.getPath(); } --> filename2 = first file, filename2 = second file, ... filename2 = last file --> end loop If you want all files you can use a list or an array.
1st May 2019, 5:51 PM
Denise Roßberg
Denise Roßberg - avatar