Good afternoon, I get a list of files from the folder

File folder = new File("D://Photo_and_Video//");// доступ ΠΊ ΠΏΠ°ΠΏΠΊΠ΅ с Ρ„Π°ΠΉΠ»Π°ΠΌΠΈ System.out.println(folder.listFiles()); File[] listOfFiles = folder.listFiles();// ΠΏΠΎΠ»ΡƒΡ‡Π°Π΅ΠΌ список Ρ„Π°ΠΉΠ»ΠΎΠ² for (File f : listOfFiles) { if(fileName.equals(f.getName())){ ΠΊΠ°ΠΊΠΎΠΉ Ρ‚ΠΎ ΠΊΠΎΠ΄ } } 

and accordingly I check for the coincidence of names, but then a question arises: how to set the condition, do something if the folder does not contain files, that is, folder.listFiles () returns nothing?

    1 answer 1

     if(listOfFiles.length > 0) { for(File f : listOfFiles) { ... } } else { System.out.println("ΠŸΡƒΡΡ‚Π°Ρ ΠΏΠ°ΠΏΠΊΠ°"); }