avrei fatto una cosa del genere:
mi sembra funzionare.codice:public static void main(String[] args) throws IOException { System.out.println("============================="); System.out.println("| SCEGLI CONNESSIONE |"); System.out.println("============================="); File dir = new File("."); HashMap<Integer, String> options = new HashMap<>(); int counter = 0; for (File f : dir.listFiles()) { if (f.getName().toLowerCase().endsWith(".properties")) { options.put(++counter, f.getName()); } } options.put(++counter, "EXIT"); int last = counter; 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); int choose = scanner.nextInt(); if (choose == last) { System.exit(0); } else { String file = options.get(choose); System.out.println(file); } }
anche se non so se è proprio quello che inendevi tu!!

Rispondi quotando