ciao!
in una applicazione console, avrei la necessità di costruire un menu dinamico.
nel quale le voci sono costituite da i files di properties presenti nella directory.
in sostanza per ora avrei fatto questo:
il mio problema è come intercettare la scelta dell'utente.codice:public class Main { public static void main(String[] args) throws IOException, InterruptedException, JSchException, URISyntaxException { System.out.println("============================="); System.out.println("| SCEGLI CONNESSIONE |"); System.out.println("============================="); File dir = new File("."); HashMap<Integer, String> options = new HashMap<>(); int counter = 1; for (File f : dir.listFiles()) { if (f.getName().toLowerCase().endsWith(".properties")) { options.put(counter++, f.getName()); } } options.put(counter++, "EXIT"); for (Map.Entry<Integer, String> m : options.entrySet()) { String voice = m.getValue(); String replace = voice.replace(".properties", ""); System.out.println(m.getKey() + " - " + replace.toUpperCase()); } Scanner scanner = new Scanner(System.in); switch (scanner.nextInt()) { // CASE } } }
come posso aggiungere i vari case all switch in base ai record di HashMap<Integer, String> options??

Rispondi quotando

