Пожалуйста, помогите мне выяснить, как я могу получить результат, когда я выполняю поиск по определенной папке?Как вернуть количество элементов, найденных после поиска?
Также как я могу спросить пользователя, хотят ли они выполнить другой поиск?
// Importing utilities
import java.io.File;
import java.util.*;
public class FileListing
{
public static void main (String[] args)
{
// Creating a Scanner
Scanner keyboard = new Scanner(System.in);
// Specifying search location
File file = new File("D:/Music");
String[] content = file.list();
// Searching for a match
System.out.println("Enter the first few characters of the folder/file to do a lookup");
String userInput = keyboard.nextLine();
// Adding text to say what the user searched for
System.out.println("Below you will find the list of folders/files with a partial match to (" + userInput + ").");
System.out.println();
// Posting the contents
for(String folders : content)
{
if(folders.toUpperCase().startsWith(userInput.toUpperCase()))
{
System.out.println("Name: " + folders);
}
}
}
}
backticks для встроенного кода, такого как 'this' ... для создания блоков кода, отступ кода с 4 пробелами. Или выберите его и нажмите значок {} вверху. – Arjan
Спасибо, я смог добиться того, что искал. –